how to run wdio for electron test without build

41 Views Asked by At

I had installed wdio for my electron test.
it seems great, but it forces me to build and compile my app before every test,
it takes ages and slows down the process.

I am looking for a way to configure it for dev env, so it will use the electron binaries from the node modules, instead of the built app binaries.

I have tries to use:

 capabilities: [
    {
      browserName: "electron",
      // Electron service options
      // see https://webdriver.io/docs/wdio-electron-service/#configuration
      "wdio:electronServiceOptions": {
        appBinaryPath:  "node_modules/electron/dist/electron" ,
        // custom application args
        appArgs: ["./out/main/index.js"],
      },

    },
  ],

but it execute it as: node_modules/electron/dist/electron --./out/main/index.js, and electron fail for finding the starting point

looked at wdio source code, and it is adding -- to any arg, and there is no exclusion. electron documentation doesn't show a way to pass the entry point as an argument with --[some entry point arg]

so I am stuck now...

any solution

1

There are 1 best solutions below

0
Wazime On

So I had to go and read Electron source code...
there is a hidden flag called --app for setting the app entry point.

here is my capabilities section:

 capabilities: [
    {
      browserName: "electron",
      // Electron service options
      // see https://webdriver.io/docs/wdio-electron-service/#configuration
      "wdio:electronServiceOptions": {

        appBinaryPath: "node_modules/electron/dist/electron" 
        // custom application args
        appArgs: ["app=./out/main/index.js"] ,
      },
    },
  ],

this will let you run wdio for dev mode without the need to compile your app every time before testing.

you need to make sure out/main/index.js have the output of your dev build, for me I am starting npm run dev in one console,and then the test in the other.

also, YOU WANT TO TEST YOUR FINAL VERSION AS WELL, so make sure to test your built binary as well.