getLocationAbsUrl 与 getCurrentUrl
getLocationAbsUrl vs getCurrentUrl
在量角器中,全局可用的browser
对象有两个方法:
Returns the current absolute url from AngularJS.
Schedules a command to retrieve the URL of the current page.
两者之间的区别不是很清楚和明显。直到现在,我一直在使用 getCurrentUrl()
。
什么时候应该使用getLocationAbsUrl()
?它涵盖了哪些用例?
我想不起其他 selenium 语言绑定中与 getLocationAbsUrl()
类似的内容。它看起来非常适合量角器。
基本上他们应该做同样的事情,return 页面的 URL。
来自这个错误报告:
https://github.com/angular/protractor/issues/132
Selenium 的 IEDriver
似乎总是 return 第一个加载的页面,而不是当前页面。因此,量角器团队实现了对 Angular 的 $location
的 JS 调用,以始终通过 [=21= 正确地 return URL ]Javascript,不是 Webdriver 协议。
GitHub getCurrentUrl
的来源
webdriver.WebDriver.prototype.getCurrentUrl = function() {
return this.schedule(
new webdriver.Command(webdriver.CommandName.GET_CURRENT_URL),
'WebDriver.getCurrentUrl()');
};
使用 schedule()
-> command()
包装器解决来自 WebDriver.getCurrentUrl()
的承诺
GitHub Protractor.getLocationAbsUrl
的来源
functions.getLocationAbsUrl = function(selector) {
var el = document.querySelector(selector);
if (angular.getTestability) {
return angular.getTestability(el).
getLocation();
}
return angular.element(el).injector().get('$location').absUrl();
};
只是 $location.absUrl()
的包装器,等待 AngularJS 库加载
当前 URL 与绝对 URL
给定的应用程序 URL:
http://www.example.com/home/index.html#/Home
当前 URL 解析为更多的 URI
/home/index.html#/Home
绝对URL解析为
http://www.example.com/home/index.html#/Home
什么时候你想使用绝对URL:你想使用完整域URL,而不是本地导航(URI),你想要 Absolute URL.
如果您的应用程序调用 当前 URL,您的测试应该调用 getCurrentUrl()
。
如果您的代码请求 Absolute URL,您的测试应该调用 getLocationAbsUrl()
.
如前所述
getLocationAbsUrl - returns 当前位置的完整路径。
browser.get('<a href="http://angular.github.io/protractor/#/api" rel="nofollow">http://angular.github.io/protractor/#/api</a>');
期望(browser.getLocationAbsUrl())
.toBe('<a href="http://angular.github.io/protractor/#/api" rel="nofollow">http://angular.github.io/protractor/#/api</a>');
getCurrentUrl 用于承诺(计划)以检索当前页面的 URL。通常,您只会在安排时使用 getCurrentUrl。
webdriver.WebDriver.prototype.getCurrentUrl = function()
{
return this.schedule(new webdriver.Command(webdriver.CommandName.GET_CURRENT_URL),'WebDriver.getCurrentUrl()');
}
请注意,getLocationAbsUrl()
现已弃用,不应再使用。
您应该改用 getCurrentUrl()
。
这是 Protractor 的相关 Github commit。
在量角器中,全局可用的browser
对象有两个方法:
Returns the current absolute url from AngularJS.
Schedules a command to retrieve the URL of the current page.
两者之间的区别不是很清楚和明显。直到现在,我一直在使用 getCurrentUrl()
。
什么时候应该使用getLocationAbsUrl()
?它涵盖了哪些用例?
我想不起其他 selenium 语言绑定中与 getLocationAbsUrl()
类似的内容。它看起来非常适合量角器。
基本上他们应该做同样的事情,return 页面的 URL。
来自这个错误报告:
https://github.com/angular/protractor/issues/132
Selenium 的 IEDriver
似乎总是 return 第一个加载的页面,而不是当前页面。因此,量角器团队实现了对 Angular 的 $location
的 JS 调用,以始终通过 [=21= 正确地 return URL ]Javascript,不是 Webdriver 协议。
GitHub getCurrentUrl
的来源webdriver.WebDriver.prototype.getCurrentUrl = function() {
return this.schedule(
new webdriver.Command(webdriver.CommandName.GET_CURRENT_URL),
'WebDriver.getCurrentUrl()');
};
使用 schedule()
-> command()
包装器解决来自 WebDriver.getCurrentUrl()
GitHub Protractor.getLocationAbsUrl
的来源functions.getLocationAbsUrl = function(selector) {
var el = document.querySelector(selector);
if (angular.getTestability) {
return angular.getTestability(el).
getLocation();
}
return angular.element(el).injector().get('$location').absUrl();
};
只是 $location.absUrl()
的包装器,等待 AngularJS 库加载
当前 URL 与绝对 URL
给定的应用程序 URL:
http://www.example.com/home/index.html#/Home
当前 URL 解析为更多的 URI
/home/index.html#/Home
绝对URL解析为
http://www.example.com/home/index.html#/Home
什么时候你想使用绝对URL:你想使用完整域URL,而不是本地导航(URI),你想要 Absolute URL.
如果您的应用程序调用 当前 URL,您的测试应该调用
getCurrentUrl()
。如果您的代码请求 Absolute URL,您的测试应该调用
getLocationAbsUrl()
.
如前所述
getLocationAbsUrl - returns 当前位置的完整路径。
browser.get('<a href="http://angular.github.io/protractor/#/api" rel="nofollow">http://angular.github.io/protractor/#/api</a>');
期望(browser.getLocationAbsUrl())
.toBe('<a href="http://angular.github.io/protractor/#/api" rel="nofollow">http://angular.github.io/protractor/#/api</a>');
getCurrentUrl 用于承诺(计划)以检索当前页面的 URL。通常,您只会在安排时使用 getCurrentUrl。
webdriver.WebDriver.prototype.getCurrentUrl = function()
{
return this.schedule(new webdriver.Command(webdriver.CommandName.GET_CURRENT_URL),'WebDriver.getCurrentUrl()');
}
请注意,getLocationAbsUrl()
现已弃用,不应再使用。
您应该改用 getCurrentUrl()
。
这是 Protractor 的相关 Github commit。