0

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?

Community
  • 1
  • 1
uKEsH
  • 3
  • 1

1 Answers1

0

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"
}
sayhan
  • 1,168
  • 1
  • 16
  • 22
  • Thanks Selcuk. I have one more doubt, if the app launch from here. how can I use the 'app' variable in Test. I have to do end to end testing electron using spectron. Note:- I'm referring the URL https://www.wintellect.com/end-end-testing-electron-apps-spectron/ – uKEsH Nov 13 '18 at 06:15
  • You can define app variable in your before hooks. – sayhan Nov 13 '18 at 07:32
  • How can I define app variable after the app launched from scripts which you mentioned above. Because they launched the app using below code var app = new Application({ path: electronPath, args: [appPath] }); But in our case, we have launched the app from scripts in package.json – uKEsH Nov 14 '18 at 07:16