Reputation: 51
I am trying to override some websockets requests for functional testing purposes.
I have tried using intercepts and mocking as advised here https://devexpress.github.io/testcafe/documentation/test-api/intercepting-http-requests/ however this only seems straightforward for HTTP and can only update status code in WSS. The messages in the WSS is in JSON which I need to override.
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();
});
Upvotes: 3
Views: 1243