-
Notifications
You must be signed in to change notification settings - Fork 18
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
Start electron without a binary (i.e. electron main.js
)
#331
Comments
We could definitely do that. I didn't know you can start Electron applications directly like this. We could introduce an Wdyt @goosewobbler ? |
electron main.js
)electron main.js
)
To add a benefit, it is much faster to start an electron app that way. Great for the code-test loop. Thank you so much. |
electron main.js
)electron main.js
)
Once this is supported by the service we should have another example / e2e directory for this too, something like |
I prototyped this in #345 but I am currently unable to test locally as running Electron like this produces EDIT: found the culprit and workaround: pnpm/pnpm#7253 Updated the PR but obviously need a different approach... |
@goosewobbler I tried it out by injecting:
to launcher.js. It started the electron app but I run the CLI manually with: 2 questions:
|
Nvm. It actually works! I registered the ready event too late (many weird bugs in my codebase lolcry). When switching to One issue that I encounter is that the app is not closed after the test finishes. I can invoke |
Interesting, I can also get the app to load manually now - also setting the appBinaryPath and appArgs as above - but when run with WDIO the specs just hang. @christian-bromann might have some ideas about how to proceed. |
Mine didn't hang. The tests work fine (except the minor inconvenience mentioned above). Interestingly I have to use the prefix |
I've updated the PR for that, still hanging, and also with |
@tanin47 Do you have any available code for this? It would be useful to see what you did to enable this without the app hanging. |
I'm working on https://superintendent.app. The code is highly complex. It's difficult to share in a productive way. I use webpack to build the code (with the watch option); This means the app is a single JS file. My issue is that the app doesn't close when the test finishes. But generally the tests work. Have written 10s of tests so far. Very productive. Can you share how to run the test in this PR? https://github.com/webdriverio-community/wdio-electron-service/pull/345/files -- I have some time to help take a look to see whether there is a difference between my app and your test app. Edit: nvm found it: |
I am unable to run the test. @goosewobbler I wonder if you know how to unblock it. Here's the error: Other tests (e.g. |
@tanin47 Thanks for taking a look - I'm stuck with the same error. Seems like a resolution issue for I also tried removing all other args (apart from |
@goosewobbler Thank you! There's something about Electron 28.x.x. I removed all args from
It should have simply started Electron, but it still fails with the Interestingly Electron 19.x.x doesn't have this issue. I also try passing I wonder if Can you try running |
I can confirm For some reason downgrading Electron below v26 results in WDIO not running with 404s for Chromedriver thrown - I'll raise a separate issue for this. v26 and above runs the tests but fails with the |
For v19, it is on my project, not |
Electron has always supported CJS, no? ESM support was introduced in v28... |
Oh I didn't know that. I tested it. It works as expected when As a side note, I feel like it might be beneficial to have a simple test js that works across all electron versions and doesn't do anything else (e.g. like preloading).
v19 is old and you will need to download the chrome driver manually. For electron v19, you will have to download "ChromeDriver 102.0.5005.61" from https://chromedriver.chromium.org/downloads. You can put it somewhere and set the wdio conf as follows:
Please don't forget to bypass the security on Mac since this is a binary downloaded from internet. Also, to switch Electron to v19, we can change I hope this is helpful. |
@tanin47 thanks for the investigation, let us know if you have any new insight or get any further with the issue blocking this feature. For now I think I will finish the last pieces of the mocking work (#368) and start to look at #412. I raised #422 to cover improving the UX around using e.g. Electron 19. |
Thank you. I'm not blocked since I can modify launcher.js directly. I think we have a good hypothesis that v19 might work. Solving #422 sounds like a good next step since it is inherently good and will help validate this hypothesis. |
Actually, my error is different. It says ENOTDIR and that the file doesn't exist. Starting Edit: debug a bit more. I think there might be something wrong with the chromedriver itself. We can see its log by adding the below to launcher.js:
In the log, it prints a valid command: However The printed command confirms that everything is sent correctly to chromedriver. This must means there's a bug in launching the process. |
I've digged a little bit deeper and am not quite sure whether the bug lies in chromedriver. I ran chromedriver manually with: Then, I fired a request from postman to:
and it works! But if the chromedriver is started from I wonder if there's some sort of security issues instead that might prevent chromedriver from functioning correctly when being spawn inside node env. |
I am unblocked. I can start the chromedriver separately and set the port in wdio.conf.ts in order to avoid wdio spawning chromedriver. It's odd that this works. |
@tanin47 That's some great debug there - thanks for your efforts, I haven't had a lot of time to dedicate to this. So you're starting Chromedriver outside of Node and it works... @christian-bromann any ideas here? Perhaps the process from https://github.com/webdriverio/webdriverio/blob/main/packages/wdio-utils/src/node/startWebDriver.ts#L86 |
Note sure, @tanin47 do you have any logs to share here? |
Let me get the log for you. I wanted to share a bit more:
There's something specific about starting chromedriver within wdio. I suspect it is either some weird env variables or security issues. I intend to debug more today. |
Nvm. I've figured out the culprit. It's the env variable: You can start 2 chromedrivers from terminal and try to create a session:
It seems In other words, if you modify the line in startWebDriver.js to: |
Nvm again. It is used by Electron. We can reproduce the error by running |
@tanin47 excellent detective work again! I had time to try This is where the NODE_OPTIONS is being set: https://github.com/webdriverio/webdriverio/blob/main/packages/wdio-local-runner/src/worker.ts#L129 @christian-bromann is If we use |
It seems like |
That makes sense. I might prototype it if I get time... |
Thank you so much folks. On a good note, wdio has been working well for me. I have 20+ tests and can run it on Windows, Mac, and Linux. On Windows, there's a different issue. I'm not sure if it is because, on Windows, As a side note, it seems there are differences between |
The Windows case is a bit different, and yes the wrapper might have an impact. I think we restrict this issue to the Mac & Linux cases and follow up as necessary.
I see. Can this be distilled into an issue or is it just something to be aware of? I finally got this working after roughly replacing |
Both WDIO and Electron utilizes Node and looks at the same set of envs. The conflicts are bound to happen. I'm not sure if it is possible to filter out all Node-related envs before starting a chrome driver (or is that even a right solution?). Thank you so much again! EDIT: Electron doesn't generally accept node config. They only accept NODE_OPTIONS. In packaged app, it is disallowed. (ref). To answer the question, we can open a feature request to WDIO to support configuring NODE_OPTIONS for chromedriver. Today the current NODE_OPTIONS (which is intended for WDIO / npm / build env itself) is accidentally carried over to chromedriver / Electron, and that is problematic. |
Ok, well this is definitely a discussion for the WDIO issue - can you create one and link it here? I got somewhere in replacing |
WDIO no longer uses |
Being optimistic, I might be able to get this into 7.0.0... Let's see. |
I'd like to avoid building the full binary with electron-builder. I wonder if I can use wdio with
electron main.js
instead. This would be really helpful. Thank you.Edit: to add a bit more info, I was trying to make
run.sh
which containselectron main.js
and simulates a binary. But it didn't work.The text was updated successfully, but these errors were encountered: