During a functional test, I am attempting to create a "Then" step where the current URL is verified.
After researching on SO, it appears that the proper approach is to wait for the URL to match the expected one:
Then('The URL contains {string}', function(url, callback) {
browser.wait(EC.urlContains(url), 5000)
.then(() => callback())
});
The issue arises when the condition is incorrect, as I am unable to determine the actual URL which could aid in debugging.
I attempted the following:
Then('The URL contains {string}', function(url, callback) {
browser.wait(EC.urlContains(url), 5000)
.then(() => callback())
.catch(() => { throw Error('URL was ' + location.href); });
});
However, an error occurs because location
is undefined
.
Another attempt was made with:
Then('The URL contains {string}', function(url, callback) {
browser.wait(EC.urlContains(url), 5000)
.then(() => callback())
.catch(() => { throw Error('URL was ' + browser.executeScript('location.href')); });
});
Only this output is visible:
Error: URL was ManagedPromise::19695 {[[PromiseStatus]]: "pending"}
This is due to browser.executeScript
returning only a Promise
.
What is the correct method to display the actual URL in the error message?