A command-line utility that automates Postman collections using Newman. Ideal for CI/CD pipelines, tests or updates, it handles authentication, token generation, and data-driven execution via CSV files—complete with request/response logging and built-in delays to avoid race conditions.
| # | Section |
|---|---|
| 1 | Newman CLI Overview |
| 2 | Key Features of Newman |
| 3 | Advantages Over Postman |
| 4 | Project Features |
| 5 | Prerequisites |
| 6 | Configuration |
| 7 | Script Overview (script.js) |
| 8 | Running the Script |
| 9 | Example Output |
| 10 | Next Steps |
| 11 | Conclusion |
| 12 | Support |
| 13 | References |
Newman is the headless command-line companion to Postman, built for automated API testing in CI/CD environments. It executes Postman collections without a GUI, supports multiple reporters, and can be integrated into any pipeline.
- Headless Execution: Invoke collections via CLI for non-interactive automation.
- CI/CD Integration: Works seamlessly with Jenkins, GitLab CI, CircleCI, Azure DevOps, and more.
- Custom Reporting: Output in CLI, HTML, JSON, or JUnit formats for easy consumption.
- Environment Support: Pass and export environment files to target dev, staging, or prod setups.
- Cross-Platform: Compatible with Windows, macOS, and Linux.
- Automation Focus: Designed for scripted, repeatable runs; no manual clicks required.
- Deeper CI/CD Integration: Built-in support for pipeline hooks, exit codes, and parallel runs.
- Flexible Reporting: Choose your format and level of detail for integration with external dashboards.
- Dynamic Environments: Swap environment variables on the fly via CLI flags.
- Execution Control: Fine-grained options for iteration counts, delays, and concurrency.
- Authentication Collection: Generates an access token before each data run.
- Operational Collection: Processes CSV files iteratively, one row per request.
- Logging: Streams raw request bodies and validates JSON responses to the console.
- Delay Handling:
AUTH_DELAY_MS(default 10 000 ms) between auth and operational runs.BATCH_DELAY_MS(default 20 000 ms) between different input files.
- Node.js (v14+ recommended)
- Newman installed globally:
npm install -g newman - Postman collections and environment JSON:
Authentication.postman_collectionOperationalCollection.postman_collectionEnvironment.postman_environment.json
- Optional CSV input files (each with header row + data rows)
-
Collections & Environment
Place the following files in your project root:
Authentication.postman_collection
OperationalCollection.postman_collection
Environment.postman_environment.json -
Input Files
- Ensure each CSV (e.g.,
input1.csv) has a header row followed by data rows. - Add the filenames to the
inputFilesarray at the top ofscript.js.
- Ensure each CSV (e.g.,
-
Adjustable Delays
- Modify
AUTH_DELAY_MSandBATCH_DELAY_MSconstants inscript.jsif needed.
- Modify
-
runCollections(inputFile)- Runs the auth collection to refresh the token.
- Waits
AUTH_DELAY_MS. - Runs the operational collection with
iterationDatafrom the CSV.
-
logRequestResponse(args, isResponse)- On each request: logs raw body.
- On each response: attempts JSON parse, logs parsed object or raw text.
-
getIterationCount(inputFile)- Reads CSV, counts rows minus header to determine iteration count.
-
executeAllInputFiles()- Loops through
inputFiles, callsrunCollectionsfor each. - Waits
BATCH_DELAY_MSbetween runs.
- Loops through
node script.js
Ensure you have the correct files in place and Newman installed.
Running AUTH_COLLECTION to generate token...
✔ AUTH_COLLECTION run complete.
Waiting for 10 seconds before running the UPDATE_COLLECTION...
Running UPDATE_COLLECTION with 5 iterations using input file: input1.csv
→ Request: {"username":"user1","action":"update"}
← Response: {"status":"success","id":12345}
…
Waiting for 20 seconds before next input file…
All collections executed. Data saved.
- Add new CSV files to
inputFilesinscript.js. - Integrate
node script.jsinto your CI/CD pipeline’s test stage. - Extend logging to write to files or external logging services.
- Implement additional error-reporting (e.g., Slack notifications).
Newman excels at automated, headless testing and CI/CD integration, while Postman’s GUI is better for manual API exploration. For teams aiming to embed API tests in a DevOps pipeline, Newman delivers greater flexibility and reliability.
For questions or issues, please open an issue in the project repository.