【发布时间】:2020-07-21 15:11:04
【问题描述】:
使用 Testcafe,我正在尝试向我的所有请求添加一个 HTTP 标头键/值对,但是当我在实时模式下检查浏览器中的网络请求时,它没有出现在请求标头中。
我想知道这是否可能是 TypeScript 的问题?我不得不修改文档中的示例代码以允许方法参数的类型为 any 以使其编译,这令人惊讶,因为我在其他地方没有看到该要求,TC 只是“处理”它。
那么两个问题:
- 我希望看到标头
wafAccessToken对出现在对http://www.google.com的请求中,但它不是 - 知道可能是什么问题吗? - 有没有办法让我的
RequestHook不在构造函数中指定确切的 URL?我只想让它匹配和修改每个请求,无论我要去哪里。
代码如下:
import { RequestHook } from 'testcafe';
export class WebSwitchHook extends RequestHook
{
constructor(requestFilterRules: any, responseEventConfigureOpts: any)
{
super(requestFilterRules, responseEventConfigureOpts);
// ...
}
async onRequest (e: any)
{
e.requestOptions.headers['wafAccessToken'] = "REDACTED";
console.log(e.requestOptions);
}
async onResponse (e: any) {
console.log(e.body);
}
}
const webSwitchHook = new WebSwitchHook("http://www.google.com", {
includeHeaders: true,
includeBody: true
});
fixture.only('Test')
.page("http://www.google.com")
.requestHooks(webSwitchHook);
test('Test', async t => {
});
【问题讨论】:
标签: testing automation automated-tests e2e-testing testcafe