【问题标题】:Comparing URL's using Protractor使用量角器比较 URL
【发布时间】:2017-09-02 07:22:36
【问题描述】:

我有一个带有 URL 的页面 -

http://localhost:7070/application/service-architecture/572RJ78544/summary

当我点击某个特定按钮时,URL 变为 -

http://localhost:7070/developer/service-architecture/572RJ78544/summary

有什么方法可以使用 Protractor 来验证这两个 URL 是否指向同一个页面?或者通过使用正则表达式或类似的东西

例如 - 比如说,服务架构和摘要是相同的

【问题讨论】:

    标签: javascript hyperlink protractor comparison anchor


    【解决方案1】:

    这不是 Protractor 特定的,更多的是 JS ;-)

    如果您已检索到 url(例如 getCurrentUrl()),您可以针对给定的 url test / match / indexOf 您当前的 url。

    我通常将test 与正则表达式一起使用,但要使用什么取决于您。

    例如:

    如果您想等待 url 从 http://example.com/foo 更改为 http://example.com/foo/bar,那么您可以在量角器中使用以下代码等待(最多 10 秒)来更改 url,否则会因 promise 被拒绝而失败

    const urlRegExp = new RegExp('http://example.com/foo');
    return browser.driver.wait(() => {
            return browser.driver.getCurrentUrl()
                .then(url => urlRegExp.test(url));
        }, 10000);
    

    希望对你有帮助

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-10-17
      • 2017-10-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-09-25
      相关资源
      最近更新 更多