11 / 65 · 14 API Testing Fundamentals · Newman and pytest for API Automation← prev⊞ allnext →☰ Read as one page
2.2Newman: Postman Collections in CI
Newman runs Postman collections from the command line, making them suitable for CI pipelines.
Basic Usage
# Run a collection with an environment
newman run collection.json --environment staging.json --reporters cli,junit
# Run with specific folder
newman run collection.json --folder "Auth" --environment staging.json
# Run with data file (data-driven testing)
newman run collection.json --iteration-data test_data.csv --reporters cli,htmlextra
# Set environment variables from command line
newman run collection.json -e staging.json --env-var "auth_token=abc123"
Newman in GitHub Actions
jobs:
api-tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
- run: npm install -g newman newman-reporter-htmlextra
- run: |
newman run tests/collection.json \
--environment tests/staging.json \
--reporters cli,junit,htmlextra \
--reporter-junit-export results.xml \
--reporter-htmlextra-export report.html
- uses: actions/upload-artifact@v4
if: always()
with:
name: api-test-report
path: |
results.xml
report.html