Joseph Freeman
Joseph Freeman

Reputation: 1784

AngularJS Protractor: waiting for a service callback?

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?

Upvotes: 2

Views: 875

Answers (1)

alecxe
alecxe

Reputation: 473833

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);

Upvotes: 1

Related Questions