I've looked at this: JavascriptError: javascript error: document unloaded while waiting for result
and it kind of works, but I'm hung up on the idea that there should be a way to do this without sleeping the browser.
Basically, our application consists of several connected single page angular apps. When we go from the login page to the user home page we trigger a page load.
When testing this flow with protractor (login to home page --> do something on home page), about 80% of the time Angular will give me:
Failed: javascript error: document unloaded while waiting for result
on the line immediately after the login information is submitted.
I can solve this problem with a sleep in "waitForNewAngularPage" immediately after the login code as such:
TEST:
helper.doSomeDBSetup();
helper.login(userEmail, password);
helper.waitForNewAngularPage("home");
performTestOnThisPage();
Wait for page code:
exports.waitForNewAngularPage = function (page) {
return browser.driver.wait(function () {
return browser.driver.getCurrentUrl().then(function (url) {
return url.indexOf(page) > -1;
});
}, TIMEOUT).then(function() {
// TODO - we shouldn't need to sleep. We need to figure out how to load angular when switching
// between different single page angular apps so that protractor doesn't get confused.
return browser.sleep(1000);
});
};
Login code:
exports.login = function (email, password) {
browser.get(browser.baseUrl + "/login");
exports.waitForNewAngularPage("login");
//login user
element(By.css('[role="email"]')).sendKeys(email);
element(By.css('[role="password"]')).sendKeys(password);
element(By.css('[role="submit"]')).click();
browser.sleep(500); // TODO - this should not require a sleep.
};
Is there any way to help protractor not get lost when transitioning between different single page angular apps?
Given that the tests don't work when using this login function without sleeps in both places it seems like protractor gets confused both before and after the page transition when we switch between apps, but I don't know how to solve it or if there's something else I should wait for.
(I've looked at https://github.com/angular/protractor/issues/2600 and similar issues and adding as many browser.waitForAngular()s doesn't fix anything without having these sleeps.)