Async nature of Angular Protractor tests with waits Async nature of Angular Protractor tests with waits selenium selenium

Async nature of Angular Protractor tests with waits


Almost all commands in Protractor are async. This means that they first needs to be resolved. This also counts for the wait, see the docs.

So in your case the commands are all executed after each other, but because the console.log() is sync it will log a result sooner than the promis of the previous line has been resolved.

Maybe this article can help you with promises if you are having troubles with them.

If you want the console.log() to take place after the previous line you can do something like this

var EC = ExpectedConditions;let loginButtonExpected = EC.presenceOf(this.loginButton);console.log('wait for login button ...');browser.driver.wait(loginButtonExpected, 2000)    .then(() => {       console.log('login button present');    });

By the way. You are using TypeScript. That means that you can also use the methods async / await, that will make your code more "sync" and the await will "hold" executing the next line before the previous line has been resolved. See also an example project on protractor github

Hope it helps