How to Run Postman Collection Using Newman - Simple Guide
To run a Postman collection using
newman, first install Newman with npm install -g newman. Then execute newman run <collection-file.json> in your terminal to run the collection and see the test results.Syntax
The basic syntax to run a Postman collection with Newman is:
newman run <collection-file.json>: Runs the specified Postman collection file.--environment <env-file.json>: (Optional) Use this flag to specify an environment file.--reporters <reporter-names>: (Optional) Choose output formats likecli,json, orhtml.
bash
newman run <collection-file.json> [--environment <env-file.json>] [--reporters cli,json,html]
Example
This example shows how to run a Postman collection file named my_collection.json using Newman and display results in the terminal.
bash
npm install -g newman newman run my_collection.json
Output
newman
\nnewman 5.3.2
\n\nโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ โ
โ Run summary โ
โ โ
โโโโโโโโโโโโโโโโโฌโโโโโโโโโโค
โ Iterations โ 1 โ
โ Requests โ 5 โ
โ Test Scripts โ 5 โ
โ Assertions โ 10 โ
โ Failed โ 0 โ
โโโโโโโโโโโโโโโโโดโโโโโโโโโโ
\nRun completed.
Common Pitfalls
Common mistakes when running Newman include:
- Not installing Newman globally with
-g, causing command not found errors. - Using incorrect file paths or names for the collection JSON file.
- Forgetting to export the collection from Postman as a JSON file before running.
- Not specifying environment files when the collection depends on environment variables.
Always verify your collection file path and install Newman properly.
bash
Wrong: newman run my_collection Right: newman run my_collection.json
Quick Reference
| Command | Description |
|---|---|
| newman run | Run a Postman collection file |
| --environment | Specify environment variables file |
| --reporters cli,json,html | Choose output report formats |
| --delay-request | Add delay between requests |
| --iteration-count | Run collection multiple times |
Key Takeaways
Install Newman globally using npm before running collections.
Use the exact JSON file exported from Postman for your collection.
Specify environment files if your collection uses variables.
Use reporters to get output in formats like CLI, JSON, or HTML.
Check file paths and names carefully to avoid errors.