@ivanc brought a technical challenge to our AMA on Playwright with @utchbe:
“In Playwright, what’s the best approach for testing pages primarily using the WebSocket protocol, including intercepting, sending, and asserting messages, especially when there’s no native WebSocket support?”
This question not only seeks to uncover advanced techniques in Playwright for WebSocket interactions but also opens the floor for shared experiences. If you’ve navigated similar challenges or have insights into this area, your contributions would greatly enrich our understanding of effective strategies in similar scenarios.
Hi Sarah, Haven’t done that with playwright but In cypress we used a websocket server. I don’t have example code in public to share but see if these help.
const WebSocketServer = require(‘ws’);
We have the websocket server running as part of the test, the app is configured to use it and we have custom commands which broadcast messages to the websocket server.
You would need to understand your websocket to mock it.
The server is configured to listen for messages and returns certain responses: