I’m using Cypress to directly connect to websocket server using browser’s websocket API. In my implementation one ‘it’ block is one test step and one ‘describe’ block is one test (I know that’s unusual.)
E.g.:
`it("Send a message to WSS", (done) => {
ws.onopen = () => {
ws.send(Message);
done();
};
});
it("Close WSS connection", (done) => {
ws.close();
ws.onclose = () => {
done();
};
});`
Everything works fine when I run the tests individually in Test Runner, but when I run a test suite w/ multiple tests (each test opening & closing the connection) more often than not the first test passes and the 2nd fails upon establishing connection. I’m getting back 200 w/ a failed handshake message.
But it’s very flaky. Sometimes 2 tests pass and the 3rd one fails. Sometimes they all pass.
I’d be grateful for any ideas or workarounds.
I tried hard waiting after each test/each file w/ 1 describe block so the session clears in the infrastructure but to no avail.