Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[web-test-runner] Browser Launcher for Electron #2136

Open
trusktr opened this issue Mar 10, 2023 · 5 comments
Open

[web-test-runner] Browser Launcher for Electron #2136

trusktr opened this issue Mar 10, 2023 · 5 comments

Comments

@trusktr
Copy link

trusktr commented Mar 10, 2023

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

@Westbrook
Copy link
Member

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

@trusktr trusktr changed the title [web-test-runner] Run in Electron [web-test-runner] Browser Launcher for Electron Mar 21, 2023
@trusktr
Copy link
Author

trusktr commented Sep 30, 2024

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!

@Westbrook
Copy link
Member

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!

@trusktr
Copy link
Author

trusktr commented Sep 30, 2024

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

export type ProductType = 'chromium' | 'firefox' | 'webkit';

const validProductTypes: ProductType[] = ['chromium', 'firefox', 'webkit'];

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:

this.debugBrowser = await playwright[this.product].launch({

const browser = await playwright[this.product].launch(this.launchOptions);

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
Copy link
Author

trusktr commented Oct 1, 2024

Alright, here's a starting point:

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants