本文介绍了getLocationAbsUrl VS getCurrentUrl的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在量角器,全球可用的浏览器对象有两种方法:

In protractor, globally available browser object has two methods:



从AngularJS返回当前绝对URL。



调度命令检索当前页面的URL。

这是不是很清楚,明显的是什么两者之间的区别。为了这一刻,我已经使用 getCurrentUrl()

It is not quite clear and obvious what is the difference between the two. To this very moment, I've been using getCurrentUrl() only.

我们什么时候应该使用 getLocationAbsUrl()?它涵盖使用情况?

When should we use getLocationAbsUrl()? Which use-cases does it cover?

我不记得在其他硒语言绑定类似于 getLocationAbsUrl()东西。它看起来pretty多少量角器特定-

I cannot recall anything similar to getLocationAbsUrl() in other selenium language bindings. It looks pretty much protractor-specific.

推荐答案

的GitHub源getCurrentUrl

webdriver.WebDriver.prototype.getCurrentUrl = function() {
  return this.schedule(
      new webdriver.Command(webdriver.CommandName.GET_CURRENT_URL),
      'WebDriver.getCurrentUrl()');
};

使用时间表() - > 命令()包装解决从一个承诺 WebDriver.getCurrentUrl()

Uses the schedule() -> command() wrappers to resolve a promise from 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 VS绝对网址

给定应用,网址:

http://www.example.com/home/index.html#/Home

当前网址的解析为更多的URI的

Current URL resolves to more of a URI

/home/index.html#/Home

绝对URL 的解析为

http://www.example.com/home/index.html#/Home

当你想使用绝对网址::您要使用的全域网址,而不是本地导航(URI),你希望的绝对URL 的。

When do you want to use absolute URL: You want to use the Full Domain URL, rather than the local navigation (URI), you want the Absolute URL.


  • 如果您的应用程序,使针对的当前URL通话的,你的测试应该叫 getCurrentUrl()

  • If your application makes calls for the Current URL, your tests should call getCurrentUrl().

如果您code,使请求的绝对URL 的,你的测试应该叫 getLocationAbsUrl()

If your code makes requests for Absolute URL, your tests should call getLocationAbsUrl().

这篇关于getLocationAbsUrl VS getCurrentUrl的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-23 19:17