Running protractor from Jenkins - node.js

I am trying to run protractor on windows from the command line.
If I directly type the command:
webdriver-manager start
It works great.
However, from within jenkins, it keeps throwing:
'webdriver-manager' is not recognized as an internal or external command,
operable program or batch file.
My env vars seems ok, since the java and npm works fine from Jenkins.
Any idea?

As it turned out I simply forgot putting the C:\Users\USERNAME\AppData\Roaming\npm folder on the System variables and only configured it as my user path.
See elgalu's answer for your next problem though...

Install Protractor globally in the Jenkins machine, for this you may need to ssh into the Jenkins machine that run the tests:
ssh your-jenkins-server
npm -g install protractor
# update webdriver in the Jenkins machine
webdriver-manager update
# test it works
webdriver-manager start
Once you have that setup and running your next problem will probably be running Protractor headless unless your Jenkins machine has a display available and an installed windows manager like Ubuntu Desktop.

Related

'webdriver-manager start' step is getting stuck while executing in cmd

After installing protractor and trying to execute: webdriver-manager start in the command terminal, the following error is thrown:
[17:39:27] I/start - seleniumProcess.pid: undefined
[17:39:27] W/start - Selenium Standalone server encountered an error: Error: spawn cmd ENOENT.
I pasted the latest chrome driver, gecko driver and selenium standalone in npm\node_modules\protractor\node_modules\webdriver-manager\selenium, So I did not execute webdriver-manger update within the command terminal.
I am not able to resolve this issue, any help would be greatly appreciated!
ENOENT errors indicate that your program wasn't able to find the necessary entity to proceed in execution, usually this is a file, directory, symlink, pipe, etc...
In your particular case it couldn't find: the Selenium Standalone server binary
This is because instead of following protractor documentation and executing webdriver-manager update to get the necessary binaries to start a Selenium server you simply pasted the binaries in a location that you thought protractor would use to find said binaries. This location is incorrect, so you're unable to start the Selenium server properly. You can see where global npm_modules are installed on your system by executing a: npm list -g.
Typically this on Unix based systems this location is: /usr/local/lib/node_modules
And on Windows:
%USERPROFILE%\AppData\Roaming\npm\node_modules
In order to resolve this issue I would recommend you follow the documentation as it's stated or search through protractor's source code to see where the binaries are actually stored.
Maybe you could try the following and see if this helps resolve your issue, directly from their documentation:
Use npm to install Protractor globally with:
npm install -g protractor
This will install two command line tools, protractor and webdriver-manager. Try running protractor --version to make sure it's working.
The webdriver-manager is a helper tool to easily get an instance of a Selenium Server running. Use it to download the necessary binaries with:
webdriver-manager update
Now start up a server with:
webdriver-manager start
This will start up a Selenium Server and will output a bunch of info logs.
Hopefully that helps!
just add to your PATHs C:\Windows\System32

wedriverio jenkins - npm command not found error

I am trying to run webdriverio test from jenkins and following this . I installed nodeJS plugin for jenkins and under global tool config, for NodeJS , added a name and installation directory as /usr/local/bin (node executable is in this folder)
In Jenkins, in project config , under build environment, I have checked
Provide Node & npm bin/ folder to PATH and chosen the node installation name from previous step
But when I am trying to run npm install
npm test ,by adding these commands under execute shell under Build and building it, I receive this error
Building in workspace /Users/Shared/Jenkins/Home/workspace/wdio-project
[wdio-project] $ /bin/sh -xe /Users/Shared/Jenkins/tmp/hudson1478028169114509075.sh
+ npm install
/Users/Shared/Jenkins/tmp/hudson1478028169114509075.sh: line 2: npm: command not found
Build step 'Execute shell' marked build as failure
Finished: FAILURE
In case someone is looking for same issue, I resolved the above error by adding export PATH=/usr/local/bin to the execute shell under build. This post helped me
There is currently a bug opened about this (JENKINS-26583 and JENKINS-27170)
I could workaround this bug by adding explicitly node on the PATH by adding this line :
export PATH=$PATH:/home/jenkins/.jenkins/tools/jenkins.plugins.nodejs.tools.NodeJSInstallation/node_js/bin/
I had just fixed the same issue as you did.
I wonder if my fix would also help you. When I was using the alpine-based docker image, the Jenkins can never find the npm, but when I use the debian-based docker image, problem solved immediately.
Try this export PATH=/usr/local/bin:$PATH
After installation of NodeJS restart pc
In my case this worked -
export PATH=$PATH:/usr/local/bin

Lineman spec-ci in jenkins

I have installed nodejs, npm, lineman, jenkins, and phantomjs on red hat.
I am trying to run a jenkins job that just runs lineman spec-ci to run my test-em tests. When I run this command as the jenkins user on the terminal, it runs. Unfortunately, when I run this command as a job in jenkins, it fails:
node: error while loading shared libraries: libhttp_parser.so.2: cannot open shared object file: No such file or directory
This error comes up even if I try to run npm install with the jenkins job.
The jenkins service is running under the user jenkins and if I run whoami during the jenkins build it outputs jenkins.
Any idea why I can run npm and lineman commands as the jenkins user but it fails when run as a job?
I ended up running printenv and found a variable associated with libraries. I added that variable to jenkins -> configure -> global properties.

Protractor is not recognized as an internal or external command, operable program or batch file

I have protractor installed on windows slave machine. I am trying to run my script using node index.js.
If I trigger job from jenkins to run above command it gives error like Protractor is not recognized as an internal or external command, operable program or batch file.. But when I run command directly on slave machine it execute it successfully.
You can use the Jenkins NodeJS plugin(https://wiki.jenkins-ci.org/display/JENKINS/NodeJS+Plugin) to install node and additional npm packages like protractor, grunt, etc.
After installing npm packages at global level, you can select the "Provide Node & npm bin/folder to PATH" checkbox to ensure you can run "protractor", "grunt" into shell or batch command.
Hope this helps.
I had same problem
In jenkins, just go to same directory where protractor and webdriver file is present after installing npm install -g protractor
like in build environment > cd go to same directory then
run commands with node appended to them such as
node webdriver-manager start
node protractor "path where config.js" is kept
This solution works for me!! Happy Automating
This Issue occurs because if you have installed the NodeJS after starting the Jenkins server.
The solution is simple:
Restart your Jenkins Server

Jenkins integration with Grunt

I've setup Jenkins v1.550 on Windows Server 2008 R2. It runs as a service at http://localhost:8080 for now. I'm logged into the machine as an Administrator. I've installed Node.js and can run "npm" from the command line.
I've also installed the NodeJS plugin v0.2.1 for Jenkins. I then went into the Configure System section of Jenkins, scrolled down to NodeJS installations, clicked on Add NodeJS button, gave "NodeJS" as the name, and "C:\Program Files\nodejs" as the path to the installation directory. I didn't check the "Install automatically" option as I read on the plugin page that it is only available to Linux.
I then created a new job, clicked the checkbox that said "Provide Node & npm bin/ folder to PATH", created a new build step for "Execute Windows batch command" and typed in "node --version" and "grunt --version" and saved it.
I ran the job and this is the output -
Building in workspace C:\Program Files (x86)\Jenkins\workspace\Test_1.0
[Test_1.0] $ cmd /c call C:\Windows\TEMP\hudson1381541243088903083.bat
C:\Program Files (x86)\Jenkins\workspace\Test_1.0>node --version
v0.10.24
C:\Program Files (x86)\Jenkins\workspace\Test_1.0>grunt --version
'grunt' is not recognized as an internal or external command,
operable program or batch file.
C:\Program Files (x86)\Jenkins\workspace\Test_1.0>exit 9009
Build step 'Execute Windows batch command' marked build as failure
Finished: FAILURE
It looks like it's unable to find the grunt-cli for the user account Jenkins is running under (System). I tried to installing grunt cli globally (npm install -g grunt-cli) and also grunt locally (npm install grunt). No luck.
Can someone please help?
for nice easy to configure self-installed nodejs on the machine, i have to recommend the excellent -> http://wiki.jenkins-ci.org/display/JENKINS/NodeJS+Plugin
it will install nodejs and grunt on the machine, through easy to use web front end no shell required
jenkins jobs can then simply run nodejs build steps, hey presto
steps involved :
a) install this on your jenkins instance -> http://wiki.jenkins-ci.org/display/JENKINS/NodeJS+Plugin
b) create a nodejs installation on jenkins
go to
http://URL_OF_JENKINS/jenkins/configure
NodeJS- > NodeJS installations -> Add NodeJS -> Name = "NodeJS 0.11.10", tick "Install automatically", select "Install from nodejs.org", add "grunt-cli" to globally installed packages
c) create a job with "execute NodeJS script" build task
var sys = require('sys');
sys.puts('NodeJS Test');
sys.puts('***************');
sys.puts('helloworld');
volia :)
run the job and see the nodejs script run,
from their the world is your oyster you can use grunt by ticking "Provide Node/npm bin folder to PATH" and running a "execute shell" build task
npm update
grunt
grunt --force reporting
You will need to restart the Jenkins service after installing node, presumably to cause it to refresh its cached copy of your PATH environment variable
I have grunt doing some tasks for me in Jenkins, but I went the npm script route. Grunt and grunt-cli are dev dependencies, and I have the following defined in my package.json file:
"scripts": {
"test": "node node_modules/grunt-cli/bin/grunt test"
},
In Jenkins (running on Windows), I added two post-build tasks:
npm install
npm test
We just installed NodeJs normally on the Jenkins server.
Another solution that worked for me on Windows is to use the full path to the grunt exec file, which can be found by writing "where grunt" in the command shell. I used the full path in the regular bat-file.
Had the same issue on Windows. When I manually installed node and ran npm install -g grunt-cli from command line, jenkins could not recognize the grunt command. So uninstall node, reinstall it but dont run npm install. Then restart the jenkins slave. Then from the jenkins job that runs on your specific jenkins slave, make it run a Windows batch command that runs npm install -g grunt-cli After that again restart the jenkins service. Then from the job run npm install. Then everything worked for me. If issues still persist, then uninstall the slave, and reinstall it, then everything works fine immediately.

Resources