量角器:将 URL 存储在变量中以解析 returns "undefined"
Protractor: Storing URL in a variable to parse returns "undefined"
我一直在尝试获取当前的 URL 并且我想剪掉 URL 的一部分以便在另一种方法中使用。
我尝试了很多方法,我在网上看到的一种解决方案建议使用 beforeEach()
方法。我一直在尝试这个,无论如何,this.urlString
总是 returns 未定义。
这是我目前拥有的。我一定是遗漏了一些关于为什么返回 undefined 的东西,但是我想不通。
this.urlString;
beforeEach(function () {
mainPO.navigateHome();
mainPO.clickCurrent();
browser.getCurrentUrl().then(function (url) {
return this.urlString = url;
});
});
console.log(this.urlString)
我想要做的是将 URL 存储在一个字符串中,然后解析该字符串以删除 URL 的“.com”之前的所有内容,这样我就可以获取该字符串并将其插入另一个 URL 以爬行到另一个 link.
为了获取字符串形式的 URL 值,您需要 解析 browser.getCurrentUrl()
函数调用返回的承诺 :
beforeEach(function () {
mainPO.navigateHome();
mainPO.clickCurrent();
this.urlString = browser.getCurrentUrl();
});
this.urlString.then(function (url) {
console.log(url);
});
我一直在尝试获取当前的 URL 并且我想剪掉 URL 的一部分以便在另一种方法中使用。
我尝试了很多方法,我在网上看到的一种解决方案建议使用 beforeEach()
方法。我一直在尝试这个,无论如何,this.urlString
总是 returns 未定义。
这是我目前拥有的。我一定是遗漏了一些关于为什么返回 undefined 的东西,但是我想不通。
this.urlString;
beforeEach(function () {
mainPO.navigateHome();
mainPO.clickCurrent();
browser.getCurrentUrl().then(function (url) {
return this.urlString = url;
});
});
console.log(this.urlString)
我想要做的是将 URL 存储在一个字符串中,然后解析该字符串以删除 URL 的“.com”之前的所有内容,这样我就可以获取该字符串并将其插入另一个 URL 以爬行到另一个 link.
为了获取字符串形式的 URL 值,您需要 解析 browser.getCurrentUrl()
函数调用返回的承诺 :
beforeEach(function () {
mainPO.navigateHome();
mainPO.clickCurrent();
this.urlString = browser.getCurrentUrl();
});
this.urlString.then(function (url) {
console.log(url);
});