# HTML Reporter with all optionsnewman run collection.json \ -r html \ --reporter-html-export ./reports/report.html \ --reporter-html-template ./template.hbs \ --reporter-html-title "API Test Report"# JSON Reporternewman run collection.json \ -r json \ --reporter-json-export ./reports/output.json# JUnit Reporternewman run collection.json \ -r junit \ --reporter-junit-export ./reports/junit.xml# CLI Reporter (suppress specific outputs)newman run collection.json \ -r cli \ --reporter-cli-no-summary \ --reporter-cli-no-failures
Common Use Cases
Use Case 1: CI/CD Pipeline Integration
#!/bin/bash# Jenkins/GitLab CI script for API testing# Run collection with environmentnewman run api-tests.json \ -e production.json \ -r cli,junit \ --reporter-junit-export ./test-results/junit.xml \ --bail \ --suppress-exit-code# Check exit codeif [ $? -eq 0 ]; then echo "All tests passed" exit 0else echo "Tests failed" exit 1fi
Use Case 2: Data-Driven Testing
# Test multiple user scenarios from CSVnewman run user-registration.json \ -d user-data.csv \ -e staging.json \ -r html,cli \ --reporter-html-export ./reports/registration-tests.html \ --delay-request 500 \ --timeout-request 15000
Use Case 3: Multi-Environment Testing
#!/bin/bash# Test across multiple environmentsENVIRONMENTS=("dev" "staging" "production")for env in "${ENVIRONMENTS[@]}"; do echo "Testing $env environment..." newman run collection.json \ -e "environments/${env}.json" \ -r html \ --reporter-html-export "./reports/${env}-report.html" \ --bail if [ $? -ne 0 ]; then echo "Tests failed in $env environment" exit 1 fidoneecho "All environments tested successfully"
Use Case 4: Scheduled API Monitoring
#!/bin/bash# Cron job for API health monitoring (run every 15 minutes)# */15 * * * * /path/to/api-monitor.shDATE=$(date +%Y%m%d-%H%M%S)newman run health-check.json \ -e production.json \ -r json,html \ --reporter-json-export "./logs/health-${DATE}.json" \ --reporter-html-export "./logs/health-${DATE}.html" \ --timeout-request 5000 \ --suppress-exit-code# Send alert if tests failif [ $? -ne 0 ]; then echo "API health check failed at ${DATE}" | mail -s "API Alert" admin@example.comfi
Use Environment Variables: Store sensitive data (API keys, passwords) in environment files, never hardcode in collections
Implement Proper Timeouts: Set realistic --timeout-request values based on your API’s expected response times to avoid false failures
Enable Detailed Reporting: Use multiple reporters (-r cli,html,junit) for comprehensive test results and CI/CD integration
Version Control Your Collections: Export collections from Postman and store in Git alongside your codebase for version tracking
Use Data Files for Scalability: Leverage CSV/JSON data files with -d flag for testing multiple scenarios without duplicating requests
Implement Retry Logic: For flaky tests, wrap newman commands in retry loops or use CI/CD retry mechanisms
Organize Collections by Purpose: Separate smoke tests, regression tests, and integration tests into different collections for targeted execution
Export and Archive Results: Always use --export-environment and --export-globals to capture runtime state for debugging
Secure SSL Certificates: Use --ssl-client-cert and --ssl-client-key for authenticated API testing, avoid --insecure in production
Monitor Performance: Track execution times in reports to identify slow endpoints and potential performance degradation
Troubleshooting
Issue
Solution
”newman: command not found”
Ensure Node.js is installed and newman is in PATH: npm install -g newman or use full path /usr/local/bin/newman
SSL certificate verification failures
Use --insecure flag for self-signed certificates or add CA bundle with --ssl-extra-ca-certs ca-bundle.pem
Request timeouts in CI/CD
Increase timeout with --timeout-request 30000 (30 seconds) or check network connectivity in CI environment
Environment variables not loading
Verify JSON structure matches Postman format, ensure "enabled": true for all variables, check file path is correct
Collection runs but no output
Specify reporter explicitly: -r cli or check if output is redirected. Use --verbose for detailed logging
”Cannot find module” errors
Install newman locally in project: npm install newman or verify global installation: npm list -g newman
Tests pass in Postman but fail in newman
Check for timing issues, add --delay-request 1000, verify environment variables are properly exported
Memory issues with large collections
Run collections in smaller batches using --folder flag or increase Node.js memory: NODE_OPTIONS=--max-old-space-size=4096 newman run
Docker volume mount issues
Use absolute paths: docker run -v /absolute/path:/etc/newman -t postman/newman run collection.json
Exit code always 0 despite failures
Remove --suppress-exit-code flag or check CI/CD script isn’t ignoring exit codes with `
Reporter files not generated
Ensure output directory exists, check write permissions, use absolute paths for --reporter-*-export options
Data file iterations not working
Verify CSV/JSON format matches expected structure, ensure -d flag points to correct file, check for encoding issues
Additional Resources
Exporting Collections from Postman
# Using Postman API to export collectioncurl -X GET \ 'https://api.getpostman.com/collections/<collection-uid>' \ -H 'X-Api-Key: <your-postman-api-key>' \ -o collection.json# Run exported collectionnewman run collection.json
# Run with custom reporternewman run collection.json -r htmlextra# HTMLExtra with optionsnewman run collection.json \ -r htmlextra \ --reporter-htmlextra-export ./report.html \ --reporter-htmlextra-darkTheme \ --reporter-htmlextra-title "Custom API Tests"
Parallel Execution Pattern
# Using GNU Parallel for concurrent executionparallel -j 4 newman run ::: \ auth-tests.json \ user-tests.json \ order-tests.json \ payment-tests.json# Using background jobsnewman run collection1.json -e env1.json & \newman run collection2.json -e env2.json & \newman run collection3.json -e env3.json & \waitecho "All collections completed"
This site uses cookies for analytics and to improve your experience.
See our Privacy Policy for details.