Newman Commands
Installation & Basic Run
npm install -g newman
# Basic collection run
newman run collection.json
# Run from Postman API URL
newman run https://api.getpostman.com/collections/COLLECTION_ID?apikey=API_KEY
# Run with environment file
newman run collection.json -e environment.json
# Run with globals file
newman run collection.json -g globals.json
# Run both environment and globals
newman run collection.json \
-e staging.environment.json \
-g globals.json
# Set variable directly
newman run collection.json \
--env-var "apiUrl=https://api.staging.example.com" \
--env-var "authToken=mytoken123"
Reporters
# Built-in reporters
newman run collection.json --reporters cli # Default terminal
newman run collection.json --reporters json # JSON file
newman run collection.json --reporters junit # JUnit XML
# Multiple reporters
newman run collection.json --reporters cli,junit,json \
--reporter-junit-export results/junit.xml \
--reporter-json-export results/report.json
# Install htmlextra reporter
npm install newman-reporter-htmlextra
newman run collection.json \
--reporters htmlextra \
--reporter-htmlextra-export results/report.html \
--reporter-htmlextra-title "API Test Report" \
--reporter-htmlextra-darkTheme
# Install allure reporter
npm install newman-reporter-allure
newman run collection.json --reporters allure \
--reporter-allure-export allure-results
Iteration Data & Multiple Runs
# Run collection multiple times with iteration data
# data.json or data.csv drives variables per iteration
# data.csv
# username,password,expectedStatus
# alice,pass123,200
# bob,wrong,401
# admin,adminpass,200
newman run collection.json \
-d data.csv \
--iteration-count 3 # override iteration count
# data.json
# [
# { "userId": 1, "expectedName": "Alice" },
# { "userId": 2, "expectedName": "Bob" }
# ]
newman run collection.json \
-d data.json \
-e environment.json \
--reporters cli,junit \
--reporter-junit-export results.xml
Timeouts & Delays
# Request timeout (ms)
newman run collection.json --timeout-request 5000
# Response timeout
newman run collection.json --timeout-response 10000
# Script timeout
newman run collection.json --timeout-script 3000
# Overall collection timeout
newman run collection.json --timeout 60000
# Delay between requests (ms)
newman run collection.json --delay-request 200
# Disable SSL verification
newman run collection.json --insecure
# Follow redirects
newman run collection.json --ignore-redirects
# Run specific folder in collection
newman run collection.json --folder "Authentication Tests"
Exit Codes & CI Integration
# Exit codes
# 0 โ All tests passed
# 1 โ Test failures
# 2 โ Collection or environment file error
# Fail on test failure (default behavior)
newman run collection.json; echo "Exit code: $?"
# GitHub Actions
# .github/workflows/api-tests.yml
# - name: Run API tests
# run: |
# newman run collection.json \
# -e ${{env.ENVIRONMENT}} \
# --reporters cli,junit \
# --reporter-junit-export results/results.xml
# - name: Publish results
# uses: dorny/test-reporter@v1
# if: always()
# with:
# name: Newman Tests
# path: results/results.xml
# reporter: java-junit
# GitLab CI
# test:api:
# script:
# - newman run collection.json -e env.json --reporters junit
# --reporter-junit-export report.xml
# artifacts:
# reports:
# junit: report.xml
Newman as a Node Module
const newman = require('newman');
newman.run({
collection: require('./collection.json'),
environment: require('./environment.json'),
reporters: ['cli', 'junit'],
reporter: {
junit: { export: './results/junit.xml' },
},
iterationData: require('./data.json'),
delayRequest: 100,
timeoutRequest: 5000,
}, (err, summary) => {
if (err) throw err;
if (summary.run.failures.length) {
console.error(`${summary.run.failures.length} test(s) failed`);
process.exit(1);
}
console.log('All tests passed!');
console.log(`Run time: ${summary.run.timings.completed - summary.run.timings.started}ms`);
});