Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Integrate Postman test scripts with Jenkins build server

I've downloaded the POSTMAN Chrome app in order to test some Web APIs on my local dev environment.

In addition, I've downloaded the Newman cmd-line utility for Postman.

See https://www.getpostman.com/docs/newman_intro for more info.

So the Postman app is working fine, and the cmd-line utility is working too.

However, once I integrate it with my Jenkins test server, the tests are failing.

The main problem is that it's not able to launch Newman.

In a standard cmd prompt, I can successfully run the Newman test script as :

  newman -c API-Collection.json -n 3 

running n number of times.

from cmd prompt

And in the Jenkins build server GUI, I add the build script under the "Execute Shell" option.

enter image description here

But it doesn't find Newman, as this build error shows:

  FailedConsole Output

Started by user anonymous
Building in workspace C:\Program Files (x86)\Jenkins\workspace\Web Api Test1 (Team Gecko)
[Web Api Test1 (Team Gecko)] $ "C:\Program Files\bin\sh.exe" -xe C:\Windows\TEMP\hudson2522506155962538386.sh
+ newman -c C:\Users\robertjm\Documents\POSTMAN Files\Workbench-API-Collection.json -n 3 -y 1000 --exitCode 1 -o output.json -H output.html
C:\Windows\TEMP\hudson2522506155962538386.sh: newman: command not found
Build step 'Execute shell' marked build as failure
Finished: FAILURE

If someone can assist me in resolving this path issue, I would appreciate it.

thanks, Bob

like image 514
bob.mazzo Avatar asked Apr 14 '16 19:04

bob.mazzo


2 Answers

Final solution was :

1) Add build step "Execute Windows batch command" and add two lines below:

2) change dir to newman\bin:

  cd \Users\bob\appdata\roaming\npm\node_modules\newman\bin

3) run node newman as opposed to simply trying to run newman

  node newman -c "C:\\Users\\bob\\Documents\\POSTMAN Files\\Workbench-API-Collection.json"

The two tricky parts were:

1) running newman like this newman -c myCollection.json was not working, as Jenkins could not resolve this node module as it would in a straight Win cmd prompt.

2) Trying to locate the Newman module was difficult, as it's hidden inside %appdata% folder (i.e. c:\users\bob\$appdata$ ).

I hope this helps someone in the future.

good luck.

like image 147
bob.mazzo Avatar answered Nov 15 '22 00:11

bob.mazzo


Run command "which newman" in command prommpt. It will return something like - /c/Users/user1/AppData/Roaming/npm/newman

Now use fully qualified path returned by above mentioned command in Jenkins windows batch command box -

c:/Users/user1/AppData/Roaming/npm/newman -c demo.postman_collection.json

like image 28
tiwari.vikash Avatar answered Nov 15 '22 00:11

tiwari.vikash