electron-vite-react icon indicating copy to clipboard operation
electron-vite-react copied to clipboard

Bug: running multiple playwright tests

Open IhsenBouallegue opened this issue 2 years ago • 5 comments

I used the template and ran one test. It passes no problems, but running multiple ones fails with this error Error: electron.launch: Process failed to launch!. I prepared a simple repo which has the same test duplicated. Here is a test snippet:

import { test, expect, _electron as electron } from "@playwright/test";

test("homepage has title and links to intro page", async () => {
  const app = await electron.launch({ args: [".", "--no-sandbox"] });
  const page = await app.firstWindow();
  expect(await page.title()).toBe("Electron + Vite + React");
  await page.screenshot({ path: "e2e/screenshots/example.png" });
  await app.close();
});

Link to the GitHub repository with the repro https://github.com/IhsenBouallegue/electron-pw

Steps

  • yarn install
  • yarn e2e

Expected

All tests run and pass

Actual

A test is failing because of electron.launch()

IhsenBouallegue avatar Apr 21 '23 13:04 IhsenBouallegue

Hey @lifeiscontent, I see you have added playwright support. Maybe you have some insight on how to fix this basic issue.

IhsenBouallegue avatar Apr 24 '23 09:04 IhsenBouallegue

@IhsenBouallegue I wanted this to work differently, but the way it was merged you have to first build the project to run in order for the tests to work, which in my opinion seems like an unnecessary step because it should be using vite under the hood you should be able to run both the production version and the development version e2e but currently I'm not sure how to do that, this is what I was trying to explain to @caoxiemeihao but I don't think he understood the explanation and just merged the PR.

lifeiscontent avatar Apr 28 '23 21:04 lifeiscontent

Hey @lifeiscontent after a lot of investigation and confusion. I found out that it is because of these 3 lines in the main process of Electron:

if (!app.requestSingleInstanceLock()) {
  app.quit()
  process.exit(0)
}

They prevent another instance from launching and as the E2E tests are parallel, it throws an error. I discovered this a bit too late. I completely migrated to Electron Forge and had to change the whole config, which led to me discovering this. I find it weird how no one tried to start more than one E2E test.

Possible solutions:

  • Simply remove those lines. But this has other implications, although not sure if the instance lock is really needed.
  • Run E2E tests in sequence. This is the worst one. It will take forever for a large code base.
  • Make the instance lock conditional. It will be disabled when running E2E tests.

I will leave it up to you if you want to solve this or close the issue.

IhsenBouallegue avatar May 02 '23 12:05 IhsenBouallegue

@IhsenBouallegue I wanted this to work differently, but the way it was merged you have to first build the project to run in order for the tests to work, which in my opinion seems like an unnecessary step because it should be using vite under the hood you should be able to run both the production version and the development version e2e but currently I'm not sure how to do that, this is what I was trying to explain to @caoxiemeihao but I don't think he understood the explanation and just merged the PR.

Did this problem get resolved or not yet?

adnanlah avatar Jan 30 '24 08:01 adnanlah

@adnanlah not yet

lifeiscontent avatar Jan 30 '24 21:01 lifeiscontent