Newman for CLI & CI Execution
Newman is Postman's command-line collection runner — it enables running Postman collections in CI/CD pipelines, automated scheduled runs, and build scripts. Newman transforms Postman from a manual testing tool into a fully automated API regression suite that can fail a build, generate reports, and run in Docker containers without a GUI.
Newman Setup and CI Integration
# ══════════════════════════════════════════════════════════════
# SETUP
# ══════════════════════════════════════════════════════════════
# npm install -g newman
# npm install -g newman-reporter-htmlextra # Beautiful HTML reports
# ── Basic Newman run ──────────────────────────────────────────
newman run "User API Tests.postman_collection.json" --environment staging.postman_environment.json
# ── With HTML report ──────────────────────────────────────────
newman run collection.json --environment staging.json --reporters cli,htmlextra --reporter-htmlextra-export reports/api-test-report.html
# ── Run specific folder only ──────────────────────────────────
newman run collection.json --environment staging.json --folder "Authentication"
# ── Exit code: 0 = all tests passed, non-zero = failures ──────
# CI will fail the build if Newman returns non-zero exit code
# ══════════════════════════════════════════════════════════════
# GITHUB ACTIONS INTEGRATION
# .github/workflows/api-tests.yml
# ══════════════════════════════════════════════════════════════
name: API Tests
on:
push:
branches: [main, develop]
pull_request:
branches: [main]
schedule:
- cron: '0 */6 * * *' # Run every 6 hours
jobs:
api-tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
- name: Install Newman
run: npm install -g newman newman-reporter-htmlextra
- name: Run API Tests
env:
API_BASE_URL: "https://staging.myapp.com"
API_TOKEN: "${{ secrets.STAGING_API_TOKEN }}" # From GitHub Secrets
run: |
newman run ./postman/api-tests.json --env-var "base_url=$API_BASE_URL" --env-var "auth_token=$API_TOKEN" --reporters cli,htmlextra --reporter-htmlextra-export ./reports/api-results.html --bail # Stop on first failure
- name: Upload Test Report
if: always() # Upload even if tests fail
uses: actions/upload-artifact@v4
with:
name: api-test-report
path: ./reports/api-results.html
retention-days: 30Common Mistakes
- Exporting collection with hardcoded secrets — always use environment variables for base URLs and tokens; never commit secrets to the collection JSON
- Not using --bail in CI — without --bail, Newman runs all 200 requests even after critical authentication fails; fail fast on infrastructure failures
- Ignoring exit codes — Newman's exit code tells CI whether tests passed; always configure CI to fail the build on non-zero exit
- Not generating reports — CLI output disappears when the CI job ends; always generate an HTML report and upload it as a CI artifact
Tip
Tip
Practice Newman for CLI CI Execution in small, isolated examples before integrating into larger projects. Breaking concepts into small experiments builds genuine understanding faster than reading alone.
Write test first → make it pass → clean up → repeat
Practice Task
Note
Practice Task — (1) Write a working example of Newman for CLI CI Execution from scratch without looking at notes. (2) Modify it to handle an edge case (empty input, null value, or error state). (3) Share your solution in the Priygop community for feedback.
Quick Quiz
Common Mistake
Warning
A common mistake with Newman for CLI CI Execution is skipping edge case testing — empty inputs, null values, and unexpected data types. Always validate boundary conditions to write robust, production-ready software testing code.
Key Takeaways
- Newman is Postman's command-line collection runner — it enables running Postman collections in CI/CD pipelines, automated scheduled runs, and build scripts.
- Exporting collection with hardcoded secrets — always use environment variables for base URLs and tokens; never commit secrets to the collection JSON
- Not using --bail in CI — without --bail, Newman runs all 200 requests even after critical authentication fails; fail fast on infrastructure failures
- Ignoring exit codes — Newman's exit code tells CI whether tests passed; always configure CI to fail the build on non-zero exit