#Tests with Playwright failing on Electron v35

4 messages · Page 1 of 1 (latest)

lethal crest
#

I am running a test setup with Playwright setup as described in https://playwright.dev/docs/api/class-electron and with Electron v35 in GitHub CI running on Ubuntu with xvfb I keep getting the following error:
Protocol error (Page.captureScreenshot): Cannot take screenshot with 0 width.
The code is this:

const { _electron: electron } = require('playwright');

(async () => {
  // Launch Electron app.
  const electronApp = await electron.launch({ args: ['main.js'] });

  // Evaluation expression in the Electron context.
  const appPath = await electronApp.evaluate(async ({ app }) => {
    // This runs in the main Electron process, parameter here is always
    // the result of the require('electron') in the main app script.
    return app.getAppPath();
  });
  console.log(appPath);

  // Get the first window that the app opens, wait if necessary.
  const window = await electronApp.firstWindow();
  // Print the title.
  console.log(await window.title());
  // Capture a screenshot.
  await window.screenshot({ path: 'intro.png' });
  // Direct Electron console to Node terminal.
  window.on('console', console.log);
  // Click button.
  await window.click('text=Click me');
  // Exit app.
  await electronApp.close();
})();

Failing line is the one with the screenshot call - await window.screenshot({ path: 'intro.png' });.
It does manage to succeed sometimes, but very rarely. On Windows and Mac, both on CI and locally it does not fail. On Electron v34 the same code is fine. What could be the issue?

Playwright has experimental support for Electron automation. You can access electron namespace via:

lethal crest
#

Seems like this is caused by launching xvfb with --auto-servernum, any ideas why would that be an issue? Is it possible to keep --auto-servernum option, but make it work?

#

After more testing, it seems like the cause is somewhere else.

lethal crest
#

Reliable workaround is to retry screenshotting until it succeeds. Hopefully there is a proper fix for this eventually.