question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[BUG] Playwright test runner always show test result pass when working with websocket (ws or sockiet io client)

See original GitHub issue

Context:

  • Playwright Version:“^1.27.1”
  • Operating System: Linux (Ubuntu 22.04)
  • Node.js version: v18.2.1
  • Browser: request (API testing)
  • Extra: “socket.io”: “^4.5.4”,“socket.io-client”: “^4.5.4”, “ws”: “^8.11.0”

Code Snippet

Help us help you! Put down a short code snippet that illustrates your bug and that we can run and debug locally. For example:

test(`check websocket available`, async({}) => {

    const ws = new WebSocket(`${endpoint.WEBSOCKET_HOST}/notification/inapp/register`,{
        headers: {
          Cookie: `token=1${accessToken}`
        }
    });
    ws.on('open', function (){
        ws.send("say Donnnnnnnnnnn") 
    });

})

Describe the bug

When running the test, even inputting an invalid value into the cookie field, Playwright still shows the test result as pass. I checked with socket io client also, but still the result is pass. I guess there’s something wrong with Playwright test runner when working with WebSocket client.

image

Issue Analytics

  • State:closed
  • Created 10 months ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
dgozmancommented, Dec 1, 2022

@cuongld2 That’s probably because Jest does not exit fast enough for the websocket error to be thrown. Most likely Jest will wait for the open socket connection to close before exiting, but Playwright won’t do that. I’d recommend to await things, for example:

  test('websocket connection', async () => {
    await new Promise(done => {
      const ws = new WebSocket('wss://domain/inapp/register', {
        headers: {
          Cookie: 'token=11',
        }
      });

      ws.on('open', function open() {
          ws.send("say something")
          ws.terminate()
          done()
      });
    });
  });

0reactions
cuongld2commented, Dec 3, 2022

Thank you guys, Works like a charm.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Performance issue and websocket error #158 - GitHub
My guess is there is something slow going on during startup because the first test result takes much longer to show up as...
Read more >
WebSocket - Playwright
WebSocket. The WebSocket class represents websocket connections in the page. ... Fired when the websocket receives a frame.
Read more >
WebSocket error when using Playwright on GitLab CI
The node:latest does not have the appropriate system dependencies to run the browsers. You can use the Playwright docker image. ui-test: ...
Read more >
Troubleshoot your Playwright tests and find the root cause for ...
Overview of the Open Source Root Cause project which makes it easy to find the reason for failing Playwright or Puppeteer tests.
Read more >
WebSocket Security - Heroku Dev Center
The WebSocket protocol is a young technology, and brings with it some risks ... Always process messages received on the client side as...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found