由于严格通过前端自动化工作流程的某些部分而导致的复杂性,我们需要在运行前端自动化测试之前发出HTTP请求,以设置测试数据。
使用TestCafe文档,我尝试将一些东西拼凑在一起,并且在测试运行时,http请求未得到执行。这是我的代码:
import {Selector, ClientFunction, RequestHook} from 'testcafe';
class CreateTestMove extends RequestHook {
async onRequest (event) {
event.requestOptions.method = "POST";
event.requestOptions.url = "https://api.com/move/sample";
event.requestOptions.body["companyKey"] = "xxxxxxxxx";
event.requestOptions.headers["X-Company-Secret"] = "xxxxxxxxx";
event.requestOptions.headers["X-Permanent-Access-Token"] = "xxxxxxxx"
}
}
const customHook = new CreateTestMove();
fixture `Call Create Test Move`
.before(async ctx => {
customHook;
})
我对JS不太熟悉,所以可能在这里做了明显的错误,只是不确定它是什么。
RequestHooks机制旨在模拟或记录您页面中的请求。要从测试代码发出HTTP请求,您可以尝试使用this question中描述的模块,也可以尝试使用https://github.com/DevExpress/testcafe/issues/2263 github问题的示例。