getLocationAbsUrl vs getCurrentUrl
getLocationAbsUrl vs getCurrentUrl
在量角器中,全局可用的browser
对象有两种方法:
-
getLocationAbsUrl()
返回来自 AngularJS 的当前绝对 url。
-
getCurrentUrl()
计划用于检索当前页的 URL 的命令。
两者之间有什么区别还不是很清楚和明显。直到现在,我一直在使用getCurrentUrl()
。
我们什么时候应该使用getLocationAbsUrl()
?它涵盖哪些用例?
我不记得其他硒语言绑定中getLocationAbsUrl()
类似的东西。它看起来几乎是量角器特定的。
getCurrentUrl 的 GitHub source
webdriver.WebDriver.prototype.getCurrentUrl = function() {
return this.schedule(
new webdriver.Command(webdriver.CommandName.GET_CURRENT_URL),
'WebDriver.getCurrentUrl()');
};
使用 schedule()
-> command()
包装器解析来自WebDriver.getCurrentUrl()
的承诺
GitHub source for 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 库加载
当前网址与绝对网址
给定的应用网址:
http://www.example.com/home/index.html#/Home
当前 URL 解析为更多 URI
/home/index.html#/Home
绝对网址解析为
http://www.example.com/home/index.html#/Home
何时要使用绝对 URL:要使用完整域 URL,而不是本地导航 (URI),需要绝对 URL。
如果应用程序调用当前 URL,则测试应调用
getCurrentUrl()
。如果代码发出对绝对 URL 的请求,则测试应调用
getLocationAbsUrl()
。
前所述getLocationAbsUrl - 返回当前位置的完整路径。
browser.get('http://angular.github.io/protractor/#/api');
expect(browser.getLocationAbsUrl())
.toBe('http://angular.github.io/protractor/#/api');
getCurrentUrl 在承诺(计划)中用于检索当前页面的 URL。 通常,您只会在计划时使用 getCurrentUrl。
webdriver.WebDriver.prototype.getCurrentUrl = function()
{
return this.schedule(new webdriver.Command(webdriver.CommandName.GET_CURRENT_URL),'WebDriver.getCurrentUrl()');
}
基本上他们应该做同样的事情,返回页面的URL。
从这个错误报告中:
https://github.com/angular/protractor/issues/132
似乎 Selenium 的IEDriver
总是返回第一个加载的页面,而不是当前页面。因此,量角器团队实现了对 Angular $location
的 JS 调用,以始终通过 Javascript 而不是 Webdriver 协议正确返回 URL。
请注意,getLocationAbsUrl()
现已弃用,不应再使用。您应该改用getCurrentUrl()
。
这是量角器的相关 Github 提交。
- setInteval vs setTimeout
- $(this).prop('property') vs. this.property
- Js.erb VS按钮标记-不'不起作用.为什么?
- reactjs this.refs vs document.getElementById
- Performance: NaCl vs Emscripten
- 文本表示法VS.构造函数,用于在JavaScript中创建对象
- Advantages to DOMParser vs template & innerHTML
- JavaScript-===vs===运算符性能
- 开发第三方小部件-Angular vs jQuery vs普通的旧JS
- PhantomJS(vs nightwatch.js)设置cookie错误
- Javascript events: window.event vs argument reference (funct
- 需要确认我对Servlet vs RESTful网页的理解's的差异
- "#"keyCode=222 vs 51(Chrome与Android版Chrome)-为什么有区别
- .notion vs.[]notation |插入到文本对象中
- Javascript-使用“”将toDateStringMonth从文本字符串解析为数字字符串;如果“;vs“;开关”;
- 没有框架/DLL的VS Web应用程序项目
- Eval vs execscript
- VS代码:在<脚本>标签
- Object.prototype.hasOwnProperty.call() vs Object.prototype.h
- getLocationAbsUrl vs getCurrentUrl