Protractor Failed: unexpected alert open

I am developing an Angular application and I have a problem with Protractor. The thing is that the app must have this message when unload:

alert.

In Protractor test, I am getting this error:

- Failed: unexpected alert open: {Alert text : Do you want to leave this site}
  (Session info: chrome=57.0.2987.133)
  (Driver info: chromedriver=2.26.436362 (5476ec6bf7ccbada1734a0cdec7d570bb042aa30),platform=Windows NT 10.0.14393 x86_64)

Browsing, I've found this solution:

 var alertDialog = browser.switchTo().alert();
 alertDialog.accept();

But in this case I am getting this:

- Failed: unexpected alert open: {Alert text : Do you want to leave this site}
  (Session info: chrome=57.0.2987.133)
  (Driver info: chromedriver=2.26.436362 (5476ec6bf7ccbada1734a0cdec7d570bb042aa30),platform=Windows NT 10.0.14393 x86_64)
- Failed: Error while waiting for Protractor to sync with the page: "window.getAllAngularTestabilities is not a function"

Upvotes: 4

Views: 2970

Answers (1)

Anton Shanyuk
Anton Shanyuk

Reputation: 41

Here is a workaround:

browser.executeScript('window.onbeforeunload = ()=>{}');

You can find more info here: https://github.com/angular/protractor/issues/308

Upvotes: 2

Related Questions