我正在我的 Angular 7 应用程序上执行 E2E 测试,其中我有一个测试用例,其中我从 UI 应用过滤器,并将过滤器附加到作为查询参数。
生成的 URL 如下所示:
http://localhost:4000/search?programme=1
但是当我使用 browser.getCurrentUrl()
时,它只是返回 http://localhost:4000/search
没有查询参数。
现在我正在使用 browser.getLocationAbsUrl()
,但 Protractor 本身会抛出错误,它已弃用。
it('Select GV filter and check params', () => {
searchPage.selectOnePrgram();
expect<any>(browser.getLocationAbsUrl()).toContain('program=1');
// [11:53:11] W/protractor - `browser.getLocationAbsUrl()` is deprecated, please use `browser.getCurrentUrl` instead.
});
我的问题是如何将查询参数放入我的 .spec.ts
文件中?
它是否属于 E2E 范围,或者应该在单元测试中?
最佳答案
您只需使用从 browser.getCurrentUrl()
获取的 then()
来管理 Promise。
示例代码:
browser.getCurrentUrl().then(
(res) => {
console.log(res);
// response will includes the url with query params
}
);
关于angular - 如何从 Protractor API 获取查询参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55586366/