A protractor made and waiting, why should we wait?
I thought Done would make everything work synchronously, that is, after I click the link, the click callback will happen after the click, apparently not the way it does not work.
browser.ignoreSynchronization = true;
var firstURL = "https://www.google.com/?gws_rd=ssl";
describe("test", function () {
browser.get("http://www.google.com");
it("Should be on google url", function () {
expect(browser.getCurrentUrl()).toBe(firstURL);
});
it("Should be able to type in text and click", function (done) {
var ele = element.all(by.name("q")).first();
ele.sendKeys("Protractor API");
ele.click().then(function () {
expect(true).toBe(true);
done();
});
});
it("Should be on new page", function (done) {
browser.driver.getCurrentUrl().then(function (url) {
debugger;
done();
});
});
});
GetCurrentUrl () at the bottom of the code returns the URL of the first page. How do I get the current url when I see it change in the browser from a test?
+1
source to share
1 answer
You are assuming that the promise click
will be resolved after the url changes, but since you are testing a non-angular page and you have disabled sync, it is resolved immediately. You have to wait for the url to change:
var urlChanged = function(expectedUrl) {
return function() {
return browser.getCurrentUrl().then(function(url) {
return url.indexOf(expectedUrl) > -1;
});
};
};
then in the test:
ele.click().then(function () {
browser.wait(urlChanged('google'), 5000);
done();
});
+3
source to share