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