3
votes

Im using the latest protractor version to run tests in an all angular2 app. I have one function, which navigates to the login page, does the login process and then calls browser.wait until an element, which appears after login is present. Then my actual test failes with 'Failed: Timed out waiting for asynchronous Angular tasks to finish after 11 seconds.'. However if I do not wait for the login process to finish, the test passes. So apparently I am missing something with the browser.wait function. browser.sleep(x) causes the same behaviour.

My code lookes something like this:

this.login = () => {
  browser.get(${this.baseUrl}/login);
  let emailField = element(by.id('emailID-input'));
  let passwordField = element(by.id('passwordID-input'));
  let submitBtn = element(by.id('loginSubmitId'));
  emailField.sendKeys(credentials.email);
  passwordField.sendKeys(credentials.pass);
  submitBtn.click();
//browser.driver.sleep(3000);
  return browser.wait(() => {
    return element(by.xpath('//*[@id="header"]')).isPresent()
      .then((isPresent) => {
        console.log('Header is Present;', isPresent);
        return isPresent;
      });
  });
};

In the actual test-spec I want to login before running my tests:

beforeAll(async () => {
   helpers.login().then(() => {
   console.log('logged in');
   });
});

Edit 1: I changed the wait condition to also include a timeout, but the problem persits.

let until = protractor.ExpectedConditions;
let header = element(by.xpath('//*[@id="header"]'));
return browser.wait(until.presenceOf(header), 5000);
2

2 Answers

2
votes

You need to mention the wait time in browser.wait() method. Once the maximum wait time is reached protractor will throw Timeout exception based on your wait condition. And also try to use ExpectedConditions instead of direct isPresent() method.

var EC = protractor.ExpectedConditions;
var ele = element(by.xpath('//*[@id="header"]'));
return browser.wait(EC.presenceOf(ele),5000); //It will wait for 5 secs
0
votes

In protractor there is default getPageTimeout: timeout_in_millis that is set to 10 secs. Your page is taking longer than 10 secs to load, and hence it is showing you timeout error message.

You can specify this in your conf.js file.