使用量角器比较 URL
Comparing URL's using Protractor
我有一个页面 URL -
http://localhost:7070/application/service-architecture/572RJ78544/summary
当我单击特定按钮时,URL 变为 -
http://localhost:7070/developer/service-architecture/572RJ78544/summary
有什么方法可以使用 Protractor 验证这两个 URL 指的是同一个页面吗?或者通过使用正则表达式或类似的东西
例如 - 服务架构和摘要相同
它不是 Protractor 特定的,更多的是 JS ;-)
如果您已经检索到 url(例如 getCurrentUrl()
),您可以 test
/ match
/ indexOf
您当前的 url 针对给定的 url.
我通常将 test
与正则表达式一起使用,但这取决于您想要使用什么。
例如:
如果您想等待 url 从 http://example.com/foo
更改为 http://example.com/foo/bar
那么您可以在量角器中使用以下代码等待(最多 10 秒)更改url,否则失败并拒绝承诺
const urlRegExp = new RegExp('http://example.com/foo');
return browser.driver.wait(() => {
return browser.driver.getCurrentUrl()
.then(url => urlRegExp.test(url));
}, 10000);
希望对您有所帮助
我有一个页面 URL -
http://localhost:7070/application/service-architecture/572RJ78544/summary
当我单击特定按钮时,URL 变为 -
http://localhost:7070/developer/service-architecture/572RJ78544/summary
有什么方法可以使用 Protractor 验证这两个 URL 指的是同一个页面吗?或者通过使用正则表达式或类似的东西
例如 - 服务架构和摘要相同
它不是 Protractor 特定的,更多的是 JS ;-)
如果您已经检索到 url(例如 getCurrentUrl()
),您可以 test
/ match
/ indexOf
您当前的 url 针对给定的 url.
我通常将 test
与正则表达式一起使用,但这取决于您想要使用什么。
例如:
如果您想等待 url 从 http://example.com/foo
更改为 http://example.com/foo/bar
那么您可以在量角器中使用以下代码等待(最多 10 秒)更改url,否则失败并拒绝承诺
const urlRegExp = new RegExp('http://example.com/foo');
return browser.driver.wait(() => {
return browser.driver.getCurrentUrl()
.then(url => urlRegExp.test(url));
}, 10000);
希望对您有所帮助