guy mograbi
guy mograbi

Reputation: 28708

howt o fix protractor that started failing on alerts all of a sudden

I have a project that has been running well for a long time now. Recently (couple of weeks) the system tests are failing.

After a lot of investigation we concluded that protractor fails to identify and close an alert.

The code that used to work

exports.removeFaq = function( index ){
    console.log('deleting item at',index);
    exports.getContent(index).$( '[ng-click="removeFAQ($index)"]').click();
    browser.sleep(2000);
    browser.switchTo().alert().accept();
    return browser.sleep(2000);
};

is now throwing errors:

WebDriverError: unknown error: cannot determine loading status
from unexpected alert open
  (Session info: chrome=52.0.2743.116)
  (Driver info: chromedriver=2.21.371461 (633e689b520b25f3e264a2ede6b74ccc23cb636a),platform=Linux 4.2.0-38-generic x86_64) (WARNING: The server did not provide any stacktrace information)

and (using element explorer):

> browser.switchTo().alert().accept();
UnexpectedAlertOpenError: unexpected alert open: {Alert text : are you sure you want to remove this helper content?}
  (Session info: chrome=52.0.2743.116)
  (Driver info: chromedriver=2.21.371461 (633e689b520b25f3e264a2ede6b74ccc23cb636a),platform=Linux 4.2.0-38-generic x86_64) (WARNING: The server did not provide any stacktrace information)

We've tried - waiting instead of sleeping. - sleeping for a long period - ignoring angular.

nothing seems to make any difference whatsoever.

how can I fix this?

Upvotes: 4

Views: 617

Answers (2)

alaney
alaney

Reputation: 623

We had the same issue for a couple of days. Looks like we were on chromedriver 2.21. I updated to the latest version (2.23) and that seems to have fixed the issue.

The command webdriver-manager update --chrome did not work for me so I had to download the zip and extract it to my selenium directory. Under protractor.

Note there is a new protractor major version with updated versions. So updating protractor might fix the problem too.

for protractor version 3.x
You can also modify the file node_modules/protractor/config.json with the correct version and then run webdriver-manager update

for protractor version 4.x
You should modify the file ./node_modules/protractor/node_modules/webdriver-manager/config.json instead.

Upvotes: 2

nilesh
nilesh

Reputation: 14297

How can we say for sure that sleep of 2000ms is good enough? Exactly for this reason sleeps are not recommended in tests. Instead you can use proper waits and poll for alert. This way you would know that after a certain agreed timeout, alert never showed up and test rightfully failed

  //wait maximum up to lets 5s before giving up
  browser.wait(protractor.ExpectedConditions.alertIsPresent(), 5000); 
  browser.switchTo().alert().accept();

Upvotes: 1

Related Questions