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] process.send() not working in playwright

See original GitHub issue

[Context:]

  • Playwright Version: [1.25.2]
  • Operating System: [1.25.2]
  • Node.js version: [14.17.5]
  • Browser: [Chromium]

I am trying to run playwright test by spawning a child process using child_process library

Code Snippet


//parent.js
const { spawn } = require("child_process");

var proc = spawn("npx", ["playwright","test","tests/example.spec.js"], {
    shell: true,
    stdio: ['ipc']
  });
  proc.stdout.on("data", (data) => {
    console.log("stdout: " + data); //this works
  });
  proc.on('message', function (message) {
    console.log(message) // this doesn't work
  })

//inside example.spec.js(playwright test file)
process.send("Hello from child") // doesn't work

Describe the bug

At times, I get an error saying that process.send is not a function. image

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
yury-scommented, Oct 14, 2022

The code above tries to open IPC channel between my-server and playwright test runner process, each test runs in a worker process spawned by the test runner process. So even if you open an IPC channel to the test runner you’ll still have to route the messages to workers. To avoid all of that it’d be easier to establish a connection (IPC or even http?) between the tests and my-server directly. If you only need to send messages from the tests to my-server you can probably get away with writing to stdout/stderr in the tests (with some unique prefix) and then reading that stream in my-server.

I’m going to close this bug as we are not planning to change current IPC mechanism used by the test runner.

0reactions
sjainrcommented, Oct 14, 2022

Thanks for writing @yury-s.

  • My idea was actually to trigger playwright tests via an API call.

  • I am spawning a child process and running playwright tests inside it.

  • And while doing so, I want to send some messages like data from the UI, etc… from my playwright child process to my parent process i.e. my API so that I can send those messages in my API response which will be used by other services.

So, for example -

//my-server
app.get("/runPlaywrightTests", async function (req, res) {
  var proc = spawn("npx", ["playwright","test","tests/example.spec.js"], {
    shell: true,
    stdio: ['ipc']
  });

let messages = [];
  proc.on('message', async function (message) { // this doesn't work
    console.log(message) // this doesn't work
    messages.push(message) // this doesn't work
  })

  proc.on("exit", async function (code, signal) {
    if(code==0)
      res.json({ testStatus: "success", response: messages});
    else
      res.json({ testStatus: "failure", response: messages});
  });
})
Read more comments on GitHub >

github_iconTop Results From Across the Web

navigation failed because page was closed! - You.com
Running the Firefox build of Playwright from ms-playwright/firefox/firefox.exe and manually opening the website also works fine. However, whenever I try to run ...
Read more >
What Is Playwright – A Tutorial on How to Use ... - LambdaTest
Run your Playwright test scripts instantly on 50+ browser and OS ... A cloud-based Playwright automation testing cloud-like LambdaTest solves the problems ......
Read more >
Browser.Playwright — RPA Framework documentation
Compared to Selenium, these do not require their own browser process. To get a clean environment a test can just open a new...
Read more >
Puppeteer and Playwright chrome headful bugs when making ...
These phenomena are related to Chromium itself and not Puppeteer nor Playwright. If you are suffering from performance issues during ...
Read more >
Perl client for Playwright - metacpan.org
However, depending on your node installation this may not work due to ... an await() with playwright-perl you are waiting on a remote...
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