0
votes

I am using protractor framework Jasmine runner for Angular testing. I can click on each item if it has css selector. Now one problem is there is a delete button in my app. if I click delete button, there is a window notification message which have two options ok, cancel. I cannot see any css selector for this by which I can click ok in the running test. As a result test is failed.

I am explaining with my code.

my html code

<mat-card-actions>
                    <button mat-raised-button color="warn" (click)="onDeleteUser(selectedUser)" class="btn btn-default t-delete-user" [disabled]="!selectedUser.userId">{{ 'Delete'}}</button>
</mat-card-actions>

My Typscript Code

onDeleteUser( user ) {
    if ( window.confirm( this.translateService.instant( "DeleteUser" )) ) {
        this.userService.delete( this.selectedUser ).subscribe(
            succ => {
                this.notificationSerice.showOK( this.translateService.instant( "UserDeleted" ) );
                this.selectedUser = null;
                this.selectedUserRole = null;
                this.loadUserPage();
            },
            err => this.notificationSerice.showError(  this.translateService.instant( "CouldNotDeleteUser" ))
        );
    }
}

In Protractor Test I wrote in this way

let deleteUser = element(by.css('.t-delete-user'));

it('Delete button is clicked and a pop up message is appeared', async () => {
    await click.onto(deleteUser);
    //click.onto(ok);
    // but do not know how can I click ok from the window message

});

I attached an image of the message enter image description here

1

1 Answers

0
votes

Try this

browser.switchTo().alert().accept();

if that doesn't work try this one

browser.ignoreSynchronization = true;
browser.switchTo().alert().accept();
browser.ignoreSynchronization = false;

For more info refer to https://seleniumhq.github.io/selenium/docs/api/javascript/module/selenium-webdriver/lib/webdriver_exports_AlertPromise.html