I'm trying to capture all the requests that occur during the test. My application uses WebSocket and with the intercept command I can't catch wss requests. Is there any way to do this?
I'm trying to capture all the requests that occur during the test. My application uses WebSocket and with the intercept command I can't catch wss requests. Is there any way to do this?
I don't think web sockets can be caught directly by the intercept command.
One approach is to observe the results of ws communication, as shown here Testing a websocket application with Cypress between two instance of Cypress runner.
If your app talks between app and server, then start the server in /cypress/plugins/index.js and use cy.task() to get the server end of the communication.
There is also a library cypress-websocket-testing which uses rxjs, which is quite powerful but takes some getting used to.
cy.streamRequest(config, options).then(results => {
expect(results).to.not.be.undefined;
})
// When in need of a bit more flexibility
cy.stream(config).then(subject => {
subject
.pipe(
takeUntil(timer(1000)),
reduce((acc , val) => acc.concat([val]), [])
)
.subscribe({
next: (results) => {
expect(results).to.not.be.undefined;
},
error: (err) => {},
complete: done
});
});
Not supported in Cypress as of now only xhr requests are supported by cy.intercept, you need to create wesbsocket server and listen at a port and it needed to be started in another process and then using fixtures send the required response data