top of page
hand-businesswoman-touching-hand-artificial-intelligence-meaning-technology-connection-go-

Postman Newman reports in CLI and jenkins

Newman report : Newman reports provide detailed information about the results of a Postman collection run, including test outcomes, response times.

This blog is expecting that you have basic knowledge of postman. you have created your collection in postman. Now we are going to learn run collection in CLI and generating newman reports.

before jump on reports we need to ready the setup for reports

  1. Installed node.js: for installing node.js we need to download node.js latest version, you can choose according to your system, if you have windows select Windows option, if you have Mac system select macOS option and so on .

2.Set environment path: Right click on your pc select properties then select advance system setting then click on environment variable then click path then set path and save it


after set the path we can check node installed or not for that open CLI and write command node -v and enter it will show the version

3. Now install newman with the command

  npm install -g newman 

4. install html repot : for install write command

 npm install -g newman-reporter-htmlextra

set up is ready to generate reports


Run the collection : We can use the Postman CLI to manually run collections to test the functionality of API.

There are 2 ways to run collection in CLI

  1. with postman Link :

  2. By export collection on your computer:

  1. Run collection with postman link: To run collection with postman link go to postman click on your collection select share option and then select Via API it will generate token link copy that link, go to CLI and create one folder on your desktop give command

npm install -g newman

and paste your postman link next to the command




2. Run collection with your computer : First we need to export postman collection in our pc, go to the postman collection click export to your collection, create new folder in your desktop and paste your collection inside the folder.

make sure you are exporting everything which needed to run the collection like environment variable or global variable.

one more important thing here we need to save collection or environment in JSON file format only .

if you are passing data through data file we need to add data file in the collection folder , data file can be csv or json format .


Now give the command in CLI

newman run "New Collection.postman_collection.json" -g workspace.postman_globals.json -d API.csv

For run the collection we give Newman run and collection name , run with environment we give -e if you pass global environment -g command we pass.

To pass the data file we give -d and datafile name .


Generate HTML report: HTML reporter for Newman that provides the information about the collection run in HTML format. This needs to be used in conjunction with Newman so that it can recognize HTML reporting options.

we already installed html in our system now we just need to give one command

newman run "New Collection.postman_collection.json" -g workspace.postman_globals.json -d API.csv -r htmlextra

we can see this beautiful report under our Newman folder, mostly this folder create under collection folder .

We get detailed information like number of iterations, assertions, skipped tests, failed tests. From the Total Requests tab, we can get lot of information like baseurl, the request body, response header, and response format. For more details, we can to go to the Failed tests tab to check which scripts failed, status code and assertion error message.

HTML Extra is an awesome Postman/Newman reporting dashboard which enables us to display postman test results in a more interactive manner

Postman Newman integration with Jenkins:

Run collection run with Jenkins : first open jenkins in your system to open give command

java -jar jenkins.war. 

open browser: localhost 8080 it will open your Jenkins.


Make sure you installed Nodejs plugin in your jenkin

Go to Manage Jenkins > Manage Plugins and install the NodeJS plugin.

Go to Manage Jenkins > Global Tool Configuration and under NodeJS, select Add NodeJS.

Enter a name for the Node.js installation.

In Global npm packages to install, enter newman.

Select Save.

Select a Freestyle project from the options. Name your project, and select OK.


In General > Build, add a build step in the project, and choose Execute Windows batch command The build step executes a shell command. Enter a shell command to run, such as newman run ~/Desktop/"New Collection.postman_collection.json" -g workspace.postman_globals.json


Select Save to finish creating the project.


Run this build test manually by selecting Build Now in the sidebar.

Jenkins indicates that the build has failed with a red cross next to the build in the build history. This is because of the intentionally failed tests in the collection.

Select the build in the history list, then select Console Output to inspect what Newman returned.

The Html Extra report can be accessed from the location mentioned in the console output. It is highlighted in above screen shot, for reference.

So, we have reached the end of the blog. I hope you would have got a good understanding about generating Newman reports, HTML Extra reports, Running Postman Collection from CLI and executing the same in Jenkins.


31 views0 comments

Коментарі

Оцінка: 0 з 5 зірок.
Ще немає оцінок

Додайте оцінку
bottom of page