spaceagetv / electron-playwright-example

Example of multi-window Playwright testing with Electron
MIT License
78 stars 8 forks source link

Theoretically possible to test without packaging? #14

Open Nantris opened 1 year ago

Nantris commented 1 year ago

Thanks for sharing your hard work! Is there any chance in the future that tests will be able to be run without first packaging the application?

achtan commented 1 year ago

I'm looking for this as well

Nantris commented 1 year ago

@achtan theoretically yes, but if you need transpilation then no: https://github.com/microsoft/playwright/issues/19854#issuecomment-1375407099

jjeff commented 1 year ago

It should be possible now to do Playwright testing without packaging the Electron application. This repository is just an example… and to be honest, most of the work has moved to the electron-playwright-helpers repository. But you would just launch the Electron app by following the normal Playwright Electron instructions. Then you could use the electron-playwright-helpers functions for IPC, menu interactions, and (new feature!) Dialog stubbing.

achtan commented 1 year ago

@jjeff thanks for the great work. Can you please elaborate more on this? I'm not really familiar with electron nor playwright. Thanks

jjeff commented 1 year ago

In Electron, you can run your application with a script (usually npm start) that will run the original source without packaging it into an application of its own. It runs using the Electron executable which lives in your node_modules folder. However, if you are using electron-forge or electron-builder, you can build (aka "package") a freestanding application (and installers, .zip, .dmg, .etc).

Playwright's Electron functionality defaults to testing the unpackaged application. This repository and the electron-playwright-helpers library have functionality to help you to test a packaged, free-standing Electron application, more closely resembling the version that you will distribute to your end-users. The challenge of testing a packaged Electron app is discerning its component parts (executable, main javascript file, package.json, etc) in order to tell Playwright how to launch your app.

But if you're testing your unpackaged application, you can simply follow Playwright's example in their documentation. That's a good way to start.

SabFloki commented 1 year ago

Hi @jjeff - I have similar requirement with Playwright, where need to launch .exe file on windows machine running on OpenFin server and need to access menus which will take to chrome ( chromium shell ).

Will the implementation be similar as above ?

Kindly suggest.

jjeff commented 1 year ago

The helper functions in the electron-playwright-helpers package should work the same in either a packaged app or an unpackaged one. So you should be able to test menus, ipc functionality, etc, using these functions.

I don't know much about OpenFin and the configuration of Chromium that you're talking about. But if you're not loading Electron, you won't be able to test Electron's menus. Playwright should handle loading/running Electron though -- all of that is outside of the scope of this repository though.

If you haven't already looked at the electron-playwright-helpers repository, please do. Most of the work that started here has moved to there.

SabFloki commented 1 year ago

Thanks @jjeff . I haven't received the Openfin config yet. I will test it out with electron-playwright-helpers and reach out for help.

This repo has given me idea on how the approach could be taken ahead. Thanks much for this contribution.