【发布时间】:2020-06-08 21:05:19
【问题描述】:
由于严格通过前端自动化我们工作流的某些部分的复杂性,我们需要在前端自动化测试运行之前发出 HTTP 请求以设置测试数据。
使用 TestCafe 文档,我尝试将一些东西拼凑在一起,当测试运行时,http 请求没有得到执行。这是我的代码:
import {Selector, ClientFunction, RequestHook, RequestLogger} from 'testcafe';
import https from 'https';
fixture `Call Create Test Move`
.before(async ctx => {
test('test', async t => {
const executeRequest = () => {
return new Promise(resolve => {
const options = {
method: 'POST',
uri: 'https://api.com/move/sample',
headers: {
"X-Company-Secret": "xxxxxxx",
"X-Permanent-Access-Token": "xxxxxxx"
},
body: {
companyKey: 'xxxxxx'
},
json: true
};
const req = https.request(options, res => {
console.log('statusCode:', res.statusCode);
console.log('headers:', res.headers);
resolve();
});
req.on('error', e => {
console.error(e);
});
req.end();
});
};
await executeRequest();
});
});
我对 JS 不是很熟悉,所以可能在这里做了一些明显错误的事情,只是不确定是什么。
【问题讨论】:
标签: javascript testing automated-tests e2e-testing testcafe