I have been using and learning protractor for over a month now.
Despite the documentation stating that Protractor waits for Angular calls to complete (http://www.protractortest.org/#/), ensuring all steps are executed synchronously, I have not found it to be true in my scripts.
Many times, Protractor seems to run ahead, such as when clicking on a link, getting the current URL, and then verifying the URL.
Often, the URL value is stale, indicating that it was not executed after clicking the link. Below is a sample of my code from the page object and corresponding test.
I am looking for suggestions on how to ensure that all test steps are executed in order.
Page Object
this.getSPageLink(){
return element(by.xpath("//a[@title='S']"));
};
this.getLPageLink(){
return element(by.xpath("//a[@title='L']"));
};
this.goToSPage = function() {
(this.getSPageLink()).click();
*//ERROR here, sometimes second click (below) doesn't wait for first
click to complete, and complains that link for 2nd click (below) is
not found*
(this.getSLPageLink()).click();
return browser.currentURL();
*//ERROR HERE url line (e) is sometimes executed before*
}
Test Class
it('::test SL page', function() {
pageObject.goToSpage();
var currentURL=browser.getCurrentURL();
expect(currentURL).toContain("SLink");
*//ERROR HERE value in this variable "currentURL" is most of the
time Stale*
});
it('::test SL2 page', function() {
pageObject.goToLpage();
var currentURL=browser.getCurrentURL();
expect(currentURL).toContain("Link");
console.log("this line is always executed first"));
//ERROR here , this print line is always executed first
});