如何从量角器 API 获取查询参数
How to get query params from protractor APIs
我正在对我的 Angular 7 应用程序执行 E2E 测试,我有一个正在应用的测试用例来自 UI 的过滤器和过滤器附加到作为 查询参数 .
的 URL
生成的 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()
来管理承诺。
示例代码:
browser.getCurrentUrl().then(
(res) => {
console.log(res);
// response will includes the url with query params
}
);
使用 async / await 而不是 promise 链。以下应该工作。 getCurrentUrl returns 一个承诺,需要解决。参考 https://www.protractortest.org/#/api?view=webdriver.WebDriver.prototype.getCurrentUrl-
it('Select GV filter and check params', async () => {
await searchPage.selectOnePrgram();
let currentLoc = await browser.getCurrentUrl();
expect(currentLoc).toContain('program=1');
});
我正在对我的 Angular 7 应用程序执行 E2E 测试,我有一个正在应用的测试用例来自 UI 的过滤器和过滤器附加到作为 查询参数 .
的 URL生成的 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()
来管理承诺。
示例代码:
browser.getCurrentUrl().then(
(res) => {
console.log(res);
// response will includes the url with query params
}
);
使用 async / await 而不是 promise 链。以下应该工作。 getCurrentUrl returns 一个承诺,需要解决。参考 https://www.protractortest.org/#/api?view=webdriver.WebDriver.prototype.getCurrentUrl-
it('Select GV filter and check params', async () => {
await searchPage.selectOnePrgram();
let currentLoc = await browser.getCurrentUrl();
expect(currentLoc).toContain('program=1');
});