0
0
PostmanHow-ToBeginner ยท 3 min read

Generate Report Using Newman in Postman: Step-by-Step Guide

Use newman run command with the --reporters option to generate reports from Postman collections. For example, newman run collection.json --reporters cli,html runs the collection and creates an HTML report.
๐Ÿ“

Syntax

The basic syntax to generate a report using Newman is:

  • newman run <collection-file>: Runs the Postman collection file.
  • --reporters <reporter-names>: Specifies one or more reporters to generate reports (e.g., cli, html, json).
  • --reporter-<reporter-name>-export <file-path>: Exports the report to a file for the specified reporter.
bash
newman run collection.json --reporters cli,html --reporter-html-export report.html
๐Ÿ’ป

Example

This example runs a Postman collection named my_collection.json and generates both CLI and HTML reports. The HTML report is saved as my_report.html.

bash
newman run my_collection.json --reporters cli,html --reporter-html-export my_report.html
Output
newman โ†’ my_collection GET https://postman-echo.com/get [200 OK, 200ms] โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ โ”‚ executed โ”‚ failed โ”‚ โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค โ”‚ iterations โ”‚ 1 โ”‚ 0 โ”‚ โ”‚ requests โ”‚ 1 โ”‚ 0 โ”‚ โ”‚ test-scripts โ”‚ 1 โ”‚ 0 โ”‚ โ”‚ prerequest-scripts โ”‚ 1 โ”‚ 0 โ”‚ โ”‚ assertions โ”‚ 1 โ”‚ 0 โ”‚ โ”‚ total-scripts โ”‚ 2 โ”‚ 0 โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ HTML report written to my_report.html
โš ๏ธ

Common Pitfalls

Common mistakes when generating reports with Newman include:

  • Not specifying the --reporters option, which results in no report files being created.
  • Forgetting to use the --reporter-<reporter-name>-export option to save reports to files.
  • Using incorrect file paths or names for the collection or report files.
  • Running Newman without Node.js installed or without Newman installed globally.
bash
Wrong:
newman run my_collection.json

Right:
newman run my_collection.json --reporters cli,html --reporter-html-export my_report.html
๐Ÿ“Š

Quick Reference

OptionDescriptionExample
newman run Runs the Postman collectionnewman run collection.json
--reporters Specify reporters to generate (cli, html, json)--reporters cli,html
--reporter--export Export report to file for given reporter--reporter-html-export report.html
--environment Use environment variables file--environment env.json
--iteration-count Run collection multiple times--iteration-count 3
โœ…

Key Takeaways

Use the --reporters option with newman run to generate reports.
Add --reporter--export to save reports as files.
Common reporters include cli, html, and json.
Ensure correct file paths for collections and reports.
Install Node.js and Newman globally before running commands.