Replies: 15 comments
-
@Meceron You're trying to use the browser object inside your application code. WDIO won't be available there, you need to do the mocking in your spec files with the tests. |
Beta Was this translation helpful? Give feedback.
-
You can see an example of the mocking in a basic test here. The example app directory contains the app code and the e2e directory contains the tests for that app and the WDIO configuration. |
Beta Was this translation helpful? Give feedback.
-
hello, the page.ts is the base for e2e test :) first when a tried the import i got this error:
I fixed it with : but the browser object still undefined |
Beta Was this translation helpful? Give feedback.
-
Where are the tests then? It would help to know what the usage of this Page object is, because as far as I can tell, it's not being accessed in the WDIO context. Do you have this code available on github? It's hard for me to help debug this without having a repository containing a (minimal or otherwise) reproducible example. |
Beta Was this translation helpful? Give feedback.
-
Test in a 'test' directory under the main project structure, page.ts is the base for test page objects, but look lik i found the problem, the preload causing errors, because of the angulars's ESM structure, Do you have any idea how to resolve it? I cannot use require() in preload.js. |
Beta Was this translation helpful? Give feedback.
-
Do you mean ESM? Electron doesn't really support ESM properly yet though full support is on the way. Did you try a dynamic import as mentioned in the readme? |
Beta Was this translation helpful? Give feedback.
-
require('wdio-electron-service/preload'); in electron preload script cause:
if i use import() the application crash with: |
Beta Was this translation helpful? Give feedback.
-
Is this crash when running the tests or just when running the app? Or both? Did you use a conditional to wrap the import as suggested in the docs?
In the example https://github.com/webdriverio-community/wdio-electron-service/blob/main/example/app/src/preload.ts#L4 |
Beta Was this translation helpful? Give feedback.
-
Both, I try this optional imports |
Beta Was this translation helpful? Give feedback.
-
Ok I've done it. Look like all scripts loaded. But the If I not import the 'browser' object from the service I got this:
|
Beta Was this translation helpful? Give feedback.
-
Ok, update: After rework and refactors, i got these:
and I found out there is a 'contextIsolation: false,' setup in out main project, we cannot chang these setting due to a a cross-platform supports, anyone have any advice to use the preload script some how? if I require that in the preload I've got : Any advice? |
Beta Was this translation helpful? Give feedback.
-
@Meceron looks like you are getting closer. Unfortunately the service wasn't developed to support |
Beta Was this translation helpful? Give feedback.
-
@Meceron Actually I don't know if the contextIsolation is the problem here. The first error about missing handlers will be a consequence of the preload not loading correctly. Are you using ESM or CJS in your project? If you need to use CJS then you should be able to swap out the dynamic import for a EDIT: I found some issue with the CJS export which might be affecting your project if you are using CJS, I will fix this and add CJS-specific testing. |
Beta Was this translation helpful? Give feedback.
-
Its electron(CJS) + angular(ESM) but now I'm allowed to modify and clean up some legacy stuff (about 10y old project wiht full of noise). I would like to change the contextIsolation to default true. Then maybe the preload hopefully starts work. |
Beta Was this translation helpful? Give feedback.
-
Ok @Meceron, also you might want to try 4.2 which has fixed the CJS build issue. EDIT: I just tried out |
Beta Was this translation helpful? Give feedback.
-
Hello,
I've started to test an application with Electron 22.0.0. We asked for the dialog support for electron what is come true, but now I ran into some configuration errors. Somebody can help me out what did I missed? (application build on windows 'release' dir. Angular 15 app.
when i run test i got:
main.ts
preload.js
wdio.conf.ts
page.ts
package.json
Beta Was this translation helpful? Give feedback.
All reactions