ale*_*cxe 19 javascript selenium angularjs selenium-webdriver protractor
在量角器中,全局可用browser
对象有两种方法:
返回AngularJS中的当前绝对URL.
计划命令以检索当前页面的URL.
目前尚不清楚和明显两者之间有什么区别.到目前为止,我一直在使用getCurrentUrl()
.
我们应该何时使用getLocationAbsUrl()
?它包含哪些用例?
我记不起与getLocationAbsUrl()
其他selenium语言绑定类似的任何内容.它看起来非常类似于量角器.
Dav*_*ich 15
getCurrentUrl的 GitHub源代码
webdriver.WebDriver.prototype.getCurrentUrl = function() {
return this.schedule(
new webdriver.Command(webdriver.CommandName.GET_CURRENT_URL),
'WebDriver.getCurrentUrl()');
};
Run Code Online (Sandbox Code Playgroud)
使用schedule()
- > command()
wrappers来解决来自的承诺 WebDriver.getCurrentUrl()
Protractor.getLocationAbsUrl的 GitHub源代码
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();
};
Run Code Online (Sandbox Code Playgroud)
只需一个$location.absUrl()
等待AngularJS库加载的包装器
当前URL与绝对URL
给定的应用网址:
http://www.example.com/home/index.html#/Home
Run Code Online (Sandbox Code Playgroud)
当前URL解析为更多URI
/home/index.html#/Home
Run Code Online (Sandbox Code Playgroud)
绝对URL解析为
http://www.example.com/home/index.html#/Home
Run Code Online (Sandbox Code Playgroud)
您何时想要使用绝对URL:您想要使用完整域URL而不是本地导航(URI),您需要绝对URL.
如果您的应用程序调用当前URL,则应该调用您的测试getCurrentUrl()
.
如果您的代码发出绝对URL请求,您的测试应该调用getLocationAbsUrl()
.