amaitu
amaitu

Reputation: 21

Testcafe - unable to dismiss browser dialog

I have a function in my test that clicks a button (removePhoneNumberButton). When this button is clicked, a browser alert shows up.

All I'd like to do is to be able to dismiss it in order to proceed with the test, but I'm not sure how to achieve this.

I have consulted the Testcafe documentation on handling native dialogs, but to no avail.

The following:

            .setNativeDialogHandler(() => true)     }

didn't seem to work either.

Here is my code:

    this.addAndRemovePhoneNumber = async function (t, phoneNumber) {
await t
      .expect(profilePageElements.uneditablePhoneNumberInput.innerText)
        .contains(phoneNumberAfterServerSideFormatting)
        .click(profilePageElements.removePhoneNumberButton)
        .setNativeDialogHandler(() => true)     }

Thanks.

Upvotes: 2

Views: 2844

Answers (1)

Alexander Moskovkin
Alexander Moskovkin

Reputation: 1861

Call the setNativeDialogHandler function before you perform a click:

await t
  .expect(profilePageElements.uneditablePhoneNumberInput.innerText)
  .contains(phoneNumberAfterServerSideFormatting)
  .setNativeDialogHandler(() => true)
  .click(profilePageElements.removePhoneNumberButton)
  

Upvotes: 4

Related Questions