2

So, I am writing a protractor test to log into an app. When a user logs in successfully a popup notification appears stating "you have successfully logged in."

Right now I am doing a browser.sleep() to wait for the popup to pop up after the login button is clicked. I don't like doing this, on slower networks Protractor is not waiting long enough and the test is failing when I try to catch the popup or alert because alert.accept() is running too soon.

Is there a way to wait the promise from the login to return to continue on with the test?

UPDATE:

I think that I have figured it out. So I'm doing this:

LoginView.loginButton.click().then(function () {
   browser.wait(exc.alertIsPresent()).then(function () {
     App.catchAlert();
   })
});

This seems to be working, but I haven't tested it on a slower network. What do you think?

Joseph Freeman
  • 1,644
  • 4
  • 24
  • 43

1 Answers1

1

You need to wait specifically for the alert to be present. There is a specific built-in Expected Condition called alertIsPresent:

var EC = protractor.ExpectedConditions;

browser.wait(EC.alertIsPresent(), 10000);
Community
  • 1
  • 1
alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195
  • What if I am using the above and running two protractor login test on different networks. The 1st test takes 9 secs to login; the 2nd test takes 15 secs to login. Will the second test fail because it is only waiting 10 secs for the browser alert? I am wanting to actually wait the for the promise to return from the login and then check for the alert, is this possible? – Joseph Freeman Mar 20 '15 at 16:00
  • @JosephFreeman yup, the code you've posted is exactly what you need to do here. Speaking about timeout values - set the timeout to the highest value - 15 seconds (15000). It does not mean it would always wait 15 seconds, instead it would check if there is an alert continuosly every 500 ms during the 15 seconds interval. Hope that helps. – alecxe Mar 20 '15 at 19:51