Reputation: 164
I've been trying to get the current URL and am wanting to cut out parts of the URL to use in another method.
I've tried many ways, and one solution I saw online suggested using the beforeEach()
method. I've been trying this and no matter what, this.urlString
always returns undefined.
Heres what i current have. I must be missing something as to why this is returning undefined however I can't figure it out.
this.urlString;
beforeEach(function () {
mainPO.navigateHome();
mainPO.clickCurrent();
browser.getCurrentUrl().then(function (url) {
return this.urlString = url;
});
});
console.log(this.urlString)
What I want to do is store the URL in a string, then parse the string to cut out everything before the ".com" of the URL so i can take the string and plug it into another URL for crawling to another link.
Upvotes: 1
Views: 1040
Reputation: 473833
In order to get URL value as a string, you need to resolve a promise returned by browser.getCurrentUrl()
function call:
beforeEach(function () {
mainPO.navigateHome();
mainPO.clickCurrent();
this.urlString = browser.getCurrentUrl();
});
this.urlString.then(function (url) {
console.log(url);
});
Upvotes: 2