admin管理员组文章数量:1291123
Is it possible to check the location path? I'm new to AngularJS and I'm learning with a book that describes ngScenario. This package is deprecated and I'm trying to update the described test to protractor.
E.g.
expect(browser().location().path()).toEqual('/books');
bees:
expect(browser.getCurrentUrl()).toEqual('http://localhost:8080/#/books');
But I'd like to avoid http://localhost:8080/
.
Is it possible to check the location path? I'm new to AngularJS and I'm learning with a book that describes ngScenario. This package is deprecated and I'm trying to update the described test to protractor.
E.g.
expect(browser().location().path()).toEqual('/books');
bees:
expect(browser.getCurrentUrl()).toEqual('http://localhost:8080/#/books');
But I'd like to avoid http://localhost:8080/
.
2 Answers
Reset to default 10Just use the power of jasmine matchers:
expect(browser.getCurrentUrl()).toMatch(/\/#\/books$/); // /#/books at the end of url
expect(browser.getCurrentUrl()).toEndWith("/#/books");
expect(browser.getCurrentUrl()).toContain("/#/books");
where toEndWith()
is ing from an awesome jasmine-matchers
library.
Or, if you want an exact match, get the base URL:
expect(browser.getCurrentUrl()).toEqual(browser.baseUrl + "/#/books");
The getCurrentUrl() function does not return the whole baseUrl (which is http://localhost:8080/#/books). So, you can try it:
browser.driver.getCurrentUrl().then(function(url) {
return /#\/books/.test(url);
});
"test" is a function of the regex module. In the example above, the text "#/books" is being pared to the current url
本文标签: javascriptProtractor check for location pathStack Overflow
版权声明:本文标题:javascript - Protractor check for location path - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741503649a2382192.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论