Playwright · Senior · Question 18 of 77

How do you mock a WebSocket server in a Playwright test?

Show the answer

Correct answer: Use page.routeWebSocket() to intercept and answer messages

Explanation

routeWebSocket can act as the server or sit between the page and the real server to change messages.

Further reading

Problem with a question

Playwright · Senior · question 18

Test yourself

Take the Playwright · Senior quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz