量角器检查位置路径

Protractor check for location path

本文关键字:路径 位置 检查 量角器      更新时间:2023-09-26

是否可以检查位置路径?我是AngularJS的新手,我正在学习一本描述ngScenario的书。该包已被弃用,我正在尝试将所描述的测试更新为量角器。

例如

expect(browser().location().path()).toEqual('/books'); 

变为:

expect(browser.getCurrentUrl()).toEqual('http://localhost:8080/#/books');

但我想避开http://localhost:8080/

只需使用茉莉花火柴的力量:

expect(browser.getCurrentUrl()).toMatch(/'/#'/books$/);  // /#/books at the end of url
expect(browser.getCurrentUrl()).toEndWith("/#/books");
expect(browser.getCurrentUrl()).toContain("/#/books");

其中toEndWith()来自一个很棒的jasmine-matchers

或者,如果你想要一个完全匹配,获取基本URL:

expect(browser.getCurrentUrl()).toEqual(browser.baseUrl + "/#/books");

getCurrentUrl()函数不返回整个baseUrl(http://localhost:8080/#/books)。所以,你可以试试:

browser.driver.getCurrentUrl().then(function(url) {
    return /#'/books/.test(url);
});

"test"是正则表达式模块的一个函数。在上面的例子中,文本"#/books"正在与当前的url 进行比较