How do I make the Transporter parts wait or become synchronous?
I have code like this in a protractor test, it goes to the home page and we need to login and then call this function. Note. I am running this in a NODE.js environment:
function Login() {
browser.findElement(by.id('ID')).then(function (ele) {
ele.sendKeys('SomeUserName');
browser.findElement(by.id('password')).then(function (ele) {
ele.sendKeys('SomePassword');
browser.findElement(by.partialButtonText('Sign in')).then(function (ele) {
ele.click();
browser.getCurrentUrl().then(function (url) {
expect(url).toBe("http://NextURLAfterClick");
debugger;
});
});
});
});
}
But I can't get the click to light up before validation browser.getCurrentUrl()
, so what happens is I get the url of the login page, I want to get the url after the click to login.
I suspect this is a misunderstanding of how the asynchronous nature of this works.
source to share
How do I make the Protractor parts wait or become synchronous?
You can wait for the url to change with browser.wait()
:
var urlChanged = function(url) {
return function () {
return browser.getCurrentUrl().then(function(actualUrl) {
return url === actualUrl;
});
};
};
element(by.id('ID')).sendKeys('SomeUserName');
element(by.id('password')).sendKeys('SomePassword');
element(by.partialButtonText('Sign in')).click();
browser.wait(urlChanged("http://NextURLAfterClick")), 5000);
where urlChanged
, in terms selenium
, is "Custom Expected Condition".
source to share