Reputation: 686
In the current nightwatch e2e test that im a writing, I need to save the last part of the browsers current url to a variable.
The steps I need to do are the following:
Could someone give me a suggestion how I could achieve step 3 and 4?
Upvotes: 1
Views: 872
Reputation: 18634
You can do it using javascript. Below is the code for reference.
module.exports = {
'Test 1': function (browser) {
var url, urlTrimmed;
browser
.url('http://master.local')
.click('selector')
.execute(function () {
urlData = {
wholeUrl: document.URL,
trimmedURL: document.URL.split('/')[4]
};
return urlData
}, [], function (result) {
url = result.value.wholeUrl;
urlTrimmed = result.value.trimmedURL
});
browser.perform(function () {
console.log("The url is" + url);
console.log("The last part of the Url is" + urlTrimmed);
});
}
};
Upvotes: 1