Ayaz
Ayaz

Reputation: 279

Installing and configuring Protractor using batch

I am trying to configure Protractor framework using batch script. I wrote batch script for downloading and installing Node.js and named it let say "prereq.bat"

set NODEJS_FILENAME=node-v10.15.0-x64.msi
set NODEJS_URL=https://nodejs.org/dist/latest-v10.x/%NODEJS_FILENAME%
set NODEJS_DOWNLOAD_LOCATION=C:\

powershell -NoExit -Command "(New-Object Net.WebClient).DownloadFile('%NODEJS_URL%', '%NODEJS_DOWNLOAD_LOCATION%%NODEJS_FILENAME%'); exit;"
msiexec /qn /l* C:\node-log.txt /i %NODEJS_DOWNLOAD_LOCATION%%NODEJS_FILENAME%

exit

My second batch file "config.bat" is where I put all npm commands to configure protractor and other required libraries

npm install -g protractor && npm install protractor-beautiful-reporter && npm install js-yaml && webdriver-manager update

I created a simple JAVA GUI tool with a "Setup" button. On click, the two batch files are called using two separate "Runtime.getRuntime().exec()".

within JAVA code the bat files are executed using following commands:

"cmd /c start "prereq.bat";
"cmd /c start "config.bat";

The problem:

When I execute the complete solution from Eclipse IDE, everything works fine. Node is installed and then protractor is configured, But, when I export the project as runnable jar, and try to execute, Node gets installed successfully but when second batch "config.bat" is called, I am getting, "npm is not recognized" error

Solution I tried: within code, i used Process.waitFor() method so that the second batch is called only when first batch commands runs successfully. Still, getting same error.

appreciate any sort of help.

Upvotes: 0

Views: 197

Answers (1)

yong
yong

Reputation: 13712

Try add the nodejs installation directory into PATH environment variable at the beginning of your config.bat. So that the cmd.exe can find the npm binary via PATH environment variable.

// config.bat

set PATH=<Nodejs installation directory>;%PATH%
npm install -g protractor && npm install protractor-beautiful-reporter && npm install js-yaml && webdriver-manager update

Upvotes: 1

Related Questions