electronchild-processspectron

How to launch electron app using child_process in spectron testing


Is it possible to launch electron app using command line with help of require('child_process') in spectron,

Normally we launch the app using command prompt like below,

cd C:\Program Files\Project

C:\Program Files\Project>Launcher.exe test.json

So we have to automate this in spectron testing, can you please someone help on this?


Solution

  • You can define that scripts into your package.json file as a script and you can define it to run with command line script when npm triggered. Npm will perform that commands.

    For example script parameters in package.json, when you call npm test from terminal, your code execute firstly locate-directory script and after that will run run-test script:

    "scripts": {
       "locate-directory": "cd C:\Program Files\Project"
       "run-test: "C:\Program Files\Project>Launcher.exe test.json"
       "test": "npm-run-all --serial locate-directory run-test"
    }