6. Newman — CLI & GitHub Actions
API Testing · 44 pages source format
Collections that only run in Postman GUI are hobbies. Newman runs them headless in CI on every PR.
What you'll learn
- newman run
- Reporters (cli, htmlextra)
- CI integration
- Secrets in CI
Newman local
npm install -g newman (or npx newman). newman run collection.json -e environment.json.
npm install newman newman-reporter-htmlextra --save-dev
npx newman run postman/collection.json -e postman/environment.jsonDo this now
Run collection locally via Newman. Fix any failures Postman runner hid.
HTML report
newman-reporter-htmlextra gives shareable reports — attach to CI artifacts.
npx newman run postman/collection.json -r htmlextra --reporter-htmlextra-export reports/api-report.htmlDo this now
Generate HTML report. Open and find a failed assertion in under 30 seconds.
GitHub Actions
Run Newman on pull_request. Upload report on failure.
name: API Tests
on: [push, pull_request]
jobs:
newman:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
- run: npm ci
- run: npx newman run postman/collection.json -e postman/environment.json -r cli,htmlextra
- uses: actions/upload-artifact@v4
if: failure()
with:
name: newman-report
path: newman/Do this now
Add .github/workflows/api-tests.yml. Green on main.
Secrets for real APIs
GitHub Secrets for API_KEY. Never hardcode in collection — use {{apiKey}} from env.
Do this now
Document secret setup in README even if lab API needs no key.