Reputation: 15
I'm currently finding the current url with
expect(browser.getCurrentUrl()).toEqual("example.com");
I want to make it into an if statement that would the url as the condition. How could I do that?
if(browser.driver.getCurrentUrl().toEqual("example.com") == "example.com"){
//do stuff
}
This is what I tried and it did not work
Upvotes: 0
Views: 308
Reputation: 3266
getCurrentUrl()
is a promise, so you need to resolve it yourself to use the value as a conditional.
browser.getCurrentUrl().then((url) => {
if(~url.indexOf('example.com')) {
// code
}
else {
// code
}
})
Finally, Jasmine methods like toEqual
should be used strictly with test assertions. I wouldn't use them outside of an expect
statement like you have above.
Upvotes: 2