【发布时间】:2019-05-23 18:26:18
【问题描述】:
我正在尝试覆盖一些 websockets 请求以进行功能测试。
我已尝试按照此处https://devexpress.github.io/testcafe/documentation/test-api/intercepting-http-requests/ 的建议使用拦截和模拟,但这对于 HTTP 来说似乎很简单,并且只能更新 WSS 中的状态代码。 WSS 中的消息是 JSON 格式,我需要覆盖它。
import { RequestMock } from 'testcafe';
import { debug } from 'util';
const mockStream = new RegExp('test\/socket.io\/v2\/.?');
const ipUrl = 'https://example.com';
const mockedResponse = Buffer.from([0x47, 0x49, 0x46, 0x38, 0x39, 0x61, 0x01, 0x00, 0x01]);
const mock = RequestMock()
.onRequestTo(mockStream)
.respond(mockedResponse, 101, {
'access-control-allow-credentials': true,
});
fixture `Fixture`
.page(ipUrl)
.requestHooks(mock);
test('Mocking', async t => {
await t
.debug()
.click('#button')
.wait(5000)
.debug();
});
【问题讨论】:
-
您应该添加您的代码尝试以便我们能够帮助您。
-
我已经添加了。我认为它不是必需的。
-
我稍后再看看。您应该查看此指南stackoverflow.com/help/how-to-ask。遵循这些步骤将帮助您获得更好的答案。
标签: javascript websocket mocking automated-tests testcafe