Introduction
In this article, we will look at How to generate reports using Postman Tool.
Pre-requisite
Postman collection with API request should be created.
Reports are an important part of Test Automation. It helps us analyze and depict the results of tests run in a pictorial manner so that it is easy to comprehend for the QA Leads/Managers.
Let's go ahead and learn how to generate reports using Postman.
Postman reports can be generated using a tool called Newman.
- Newman is a command-line runner for Postman collections. In other words, it allows a user to run an existing Postman collection through the command line.
- Newman takes the JSON version of the collection that can be obtained by simply exporting the collection in JSON collection format or the URL of the collection which is nothing but the same JSON that’s obtained by the collection export.
We need any one of the below components to generate a report,
- Collection in JSON format - Just click the three dot icon next to the collection name and select the export option to export the collection as JSON file.
- URL of the hosted collection. (this option will appear only when you are logging with your postman account and working in workspace) or else this option will be in disabled mode.
To install newman we need to have node installed previously
Then use npm and install newman,
npm install -g newman
Generate report in CLI
Navigate to the folder which contains the collection JSON file through CLI.
Now run the collection using,
newman run <provide json file name>
The above command will run and it will display the report in the CLI in a table format.
Another way of generating a report
If we want to generate a report in HTML format then there is an npm package that helps us to generate report in HTML format.
Just install the newman-reporter-htmlextra package from npm
npm i -g newman-reporter-htmlextra
Navigate to the folder which contains the collection JSON file through CLI.
Now run the collection using the below command with the flag r and provide the report name,
newman run <provide your collection json file> -r htmlextra
newman run collectiontwo.json -r htmlextra
The HTML report will get generated and stored inside the folder name called newman(autogenerated) where your collection is present.
Just right-click that HTML file that is present inside the newman folder and then open in your favorite browser and view it.
If you want to store the HTML report in another folder then provide the folder name in the command itself which is shown below
newman run collectiontwo.json -r htmlextra <provide the path where your report should get saved>
Junit full reporter
If you want to view the test reports in XML file then use the below npm package
Just install the newman-reporter-junitfull from npm
npm i -g newman-reporter-junitfull
Navigate to the folder which contains the collection JSON file through CLI.
Now run the collection using the below command with the flag r and provide the report name.
newman run <your collection name> -r junit --reporter-junit
newman run collectiontwo.json -r junit --reporter-junit
The XML report will get generated and stored inside the folder name called newman(autogenerated) where your collection is present.
Open the XML file which is inside the newman folder to view the result.
If you want to store the XML report in another folder then provide the folder name in the command itself which is shown below
newman run collectiontwo.json -r junit --reporter-junit <provide the path where your report should get saved>
Summary
Hope this article will help you in generating reports using postman tool.
Thanks............