web icon indicating copy to clipboard operation
web copied to clipboard

[web-test-runner] Browser Launcher for Electron

Open trusktr opened this issue 2 years ago • 5 comments

It would be great to have an Electron runner. Useful for testing web apps that also access Node.js APIs.

trusktr avatar Mar 10 '23 06:03 trusktr

Would that be something you were interested in contributing on maintaining in a parallel project?

Westbrook avatar Mar 17 '23 12:03 Westbrook

Looks like Playwright has experimental support for automating Electron!

https://playwright.dev/docs/api/class-electron

This will be the easy way to add Electron support!

trusktr avatar Sep 30 '24 23:09 trusktr

If that’s so, and it fits within the current API structure, we’d be happy to accept a PR to add support for this!

Westbrook avatar Sep 30 '24 23:09 Westbrook

Looking at the code, it looks like for the most part we just need to update the product list,

https://github.com/modernweb-dev/web/blob/aadcbea59e3cf929cc0ab41775b66f866d5a9dcc/packages/test-runner-playwright/src/PlaywrightLauncher.ts#L9

https://github.com/modernweb-dev/web/blob/aadcbea59e3cf929cc0ab41775b66f866d5a9dcc/packages/test-runner-playwright/src/index.ts#L10

with one caveat: the electron launcher is under playwrite._electron with an underscore (for "experimental" I'm guessing), so we'd need to make the product list handle the underscored string, but otherwise looks like calling it has the same API so it'll just fit in. For example this would be accessing the playwright._electron API:

https://github.com/modernweb-dev/web/blob/aadcbea59e3cf929cc0ab41775b66f866d5a9dcc/packages/test-runner-playwright/src/PlaywrightLauncher.ts#L90

https://github.com/modernweb-dev/web/blob/aadcbea59e3cf929cc0ab41775b66f866d5a9dcc/packages/test-runner-playwright/src/PlaywrightLauncher.ts#L143

Because Electron is Chromium-based, it might support devtools, so we could try updating this line too:

https://github.com/modernweb-dev/web/blob/aadcbea59e3cf929cc0ab41775b66f866d5a9dcc/packages/test-runner-playwright/src/PlaywrightLauncher.ts#L93C9-L93C47

trusktr avatar Sep 30 '24 23:09 trusktr

Alright, here's a starting point:

  • https://github.com/modernweb-dev/web/pull/2818

It manages to run the Electron window non-headlessly, but then it seems to not run any tests.

It might have to do with the context and page creation, which is different than with other browsers.

I'm not sure yet how to make it work. I left a message in Playwright Discord for advice on the context handling.

trusktr avatar Oct 01 '24 01:10 trusktr