Open In App

How to generate automated test reports using Postman ?

Last Updated : 09 Jan, 2024
Improve
Improve
Like Article
Like
Save
Share
Report

Postman is the API testing tool that helps to simplify the process of developing and testing APIs (Application Programming Interface). In this article, we will explore how to not only create environments but also generate automated test reports, enhancing efficiency and reliability in the API testing workflow.

Prerequisites:

Steps to generate automated test reports using Postman :

Step 1: Open the terminal and run the below commands to download dependencies globally.

npm install -g newman
npm install -g newman-reporter-htmlextra


Step 2: Open Postman and click on the “Collections” tab. Click “New Collection” and give it a name. Add requests to your collection by clicking “Add Request.”

imresizer-1704020048364

Step 3: Open a request in your collection and write the sample API. Click on the “Tests” tab to write your test scripts using JavaScript. Write assertions to verify the response.

API used: https://postman-echo.com/get

Example Test Script:

Javascript




pm.test("Status code is 200", function () {
    pm.response.to.have.status(200);
});
 
pm.test("Response time is less than 200ms", function () {
    pm.expect(pm.response.responseTime).to.be.below(200);
});


imresizer-1704020783978

Step 4: Click on “Runner” in the top menu. Select the collection you created. Click “Run” to execute the collection, and observe the results in the “Runner” tab. You can drag your collection and move it to the run order panel.

imresizer-1704020683536

Step 5: After dropping the collection to the runner, you can see the result of tests. Now to view the detailed HTML report, Click on three dots besides the “New Collection” tab and click on export and save the collection.

imresizer-1704277454132

Step 6: Create Newman: Now run the following command in cmd to generate the test report.

newman run <Your-collection-path> -r htmlextra –reporter-htmlextra-title “Automated test reporting – Postman echo”

dwd

Step 7: Generate HTML Report: Look for Newman in the directory you wrote this command.You will see a chrome link there , View and download report.

imresizer-1704277209671

Output:

ezgifcom-video-to-gif-converter-(11)



Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads