user2880391
user2880391

Reputation: 2791

Protractor wait for Angular to load

my test is doing login in a non-angular page, and then getting to an Angular page. currently, in order for the test to work properly I'm using sleep and timeout (right after the login):

browser.sleep(5000);
browser.switchTo().defaultContent();
browser.ignoreSynchronization = false;
flow.timeout(5000);

I've tried removing each one of them, and tried also Expected condition:

var EC = protractor.ExpectedConditions;
var profilePhoto = element(By.css(".profile-photo"));
browser.wait(EC.visibilityOf(profilePhoto), 15000);

tried also using the

browser.waitForAngular();

but - any try without the sleep and timeout resulted in failure and

Error while waiting for Protractor to sync with the page: "angular could not be found on the window"

my question is -how can I make sure I got to the home page (after login) without 'sleep' or 'timeout'?

Upvotes: 2

Views: 3773

Answers (1)

rycornell
rycornell

Reputation: 717

I had the same problem earlier today. Adding browser.ignoreSynchronization = true; just before the login attempt and adding browser.wait... just after the login attempt fixed the problem:

// non-angular page
browser.get("/login");

// ignore synchronization since we're transitioning from a non-angular page to an angular page
browser.ignoreSynchronization = true;

// login
element(by.id("email")).sendKeys("username");
element(by.id("password")).sendKeys("password");
element(by.partialButtonText("Login")).click();

// wait
var EC = protractor.ExpectedConditions;
browser.wait(EC.visibilityOf(element(by.id("dashboard"))), 10000);

Upvotes: 1

Related Questions