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.htmlExample
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.htmlOutput
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
--reportersoption, which results in no report files being created. - Forgetting to use the
--reporter-<reporter-name>-exportoption 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.htmlQuick Reference
| Option | Description | Example |
|---|---|---|
| newman run | Runs the Postman collection | newman run collection.json |
| --reporters | Specify reporters to generate (cli, html, json) | --reporters cli,html |
| --reporter- | 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.