mardi 29 septembre 2015

Wait for page redirection in Protractor / Webdriver

I have a test that clicks a button and redirects to a user dashboard. When this happens Webdriver returns: javascript error: document unloaded while waiting for result.

To fix this I insert browser.sleep(2000) at the point where redirection occurs and assuming my CPU usage is low, this solves the issue. However, 2000 ms is arbitrary and slow. Is there something like browser.waitForAngular() that will wait for the angular to load on the redirected page before the expect(..)?

it('should create a new user', () => {
  $signUp.click();
  $email.sendKeys((new Date().getTime()) + '@.com');
  $password.sendKeys('12345');
  $submit.click();

  browser.sleep(2000); // Need alternative to sleep...

  // This doesn't do it...
  // browser.sleep(1);
  // browser.waitForAngular();

  $body.evaluate('user')
  .then((user) => {
    expect(user).toBe(true);
  });
});

Aucun commentaire:

Enregistrer un commentaire