Answer
What is Newman?
Newman is the command-line collection runner for Postman. It allows you to run Postman collections directly from the terminal, making it perfect for CI/CD integration.
Installation
Bash
npm install -g newman
# With HTML reporter
npm install -g newman-reporter-html
Basic Usage
Bash
# Run a collection
newman run MyCollection.json
# Run with environment
newman run MyCollection.json -e staging-environment.json
# Run with data file
newman run MyCollection.json -d testdata.csv
# Run with HTML report
newman run MyCollection.json --reporters html --reporter-html-export results/report.html
# Run with JUnit XML (for CI systems)
newman run MyCollection.json --reporters junit --reporter-junit-export results/junit.xml
Exporting from Postman
- ✓Open your Collection
- ✓Click ... → Export
- ✓Choose Collection v2.1
- ✓Save the JSON file
- ✓Run with Newman
CI/CD Integration Examples
GitHub Actions
YAML
- name: Run API Tests
run: |
npm install -g newman newman-reporter-html
newman run collection.json -e production.json --reporters cli,html \
--reporter-html-export report.html
Jenkins
Bash
newman run ${WORKSPACE}/collection.json \
-e ${WORKSPACE}/env.json \
--reporters junit \
--reporter-junit-export ${WORKSPACE}/results/newman-report.xml
Newman Options
| Flag | Description |
|---|---|
-e, --environment | Environment file |
-d, --iteration-data | Data file (CSV/JSON) |
-n, --iteration-count | Number of iterations |
--delay-request | Delay between requests (ms) |
--timeout-request | Request timeout (ms) |
--reporters | Output reporters (cli, html, junit) |
--bail | Stop on first test failure |
Advantages of Newman
- ✓No Postman UI needed — headless execution
- ✓Integrate with any CI/CD tool (Jenkins, GitHub Actions, GitLab CI, Azure DevOps)
- ✓Generate test reports automatically
- ✓Run collections programmatically in Node.js
