2

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

2
  • Hey, we are having similar issues. Did you find out what caused it and how to resolve this? Commented May 23, 2017 at 15:18
  • As unsatisfying as it may be, I'm pretty sure we just went with using the sleeps @MichielThalen (We're now using React with Nightwatch for our front end/integration tests, 2 years saw a lot of changes :P) Commented May 24, 2017 at 15:53

2 Answers 2

1

It looks like nobody's really found a better way around this, so I'll just answer for posterity. Check out the comment on the original question for what we did: Navigating from one single page angular app to another with protractor gives "javascript error: document unloaded while waiting for result"

As unsatisfying as it may be, I'm pretty sure we just went with using the sleeps @MichielThalen (We're now using React with Nightwatch for our front end/integration tests, 2 years saw a lot of changes :P)

Sign up to request clarification or add additional context in comments.

Comments

0

Try increasing your Protractor defaultTimeoutInterval in your config file.

jasmineNodeOpts: {
  defaultTimeoutInterval: 30000 
}

Also you can read more here, https://github.com/angular/protractor/blob/master/docs/timeouts.md

1 Comment

It's not that it's hitting the timeout before it executes - when it gets stuck it hangs until it hits the timeout and when it doesn't it executes after a couple seconds. Increasing the timeout would just make it hang longer in the case that protractor gets "lost" upon app transition

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.