【问题标题】:How can I use testcafe to intercept and mock websocket requests如何使用 testcafe 拦截和模拟 websocket 请求
【发布时间】: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


【解决方案1】:

目前无法拦截 WebSocket 请求。 我在 TestCafe 存储库中为此案例创建了一个issue。 跟踪它以了解我们在实施此功能方面取得的进展。

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2020-01-11
  • 2022-11-10
  • 1970-01-01
  • 1970-01-01
  • 2011-04-03
  • 1970-01-01
  • 1970-01-01
  • 2020-02-24
相关资源
最近更新 更多