How to Run Postman Collections With Newman in CI
Newman is Postman's command-line runner, so a collection that passes in the app can run unchanged in CI.
Install newman, then run newman run against your exported collection and environment. Add a JUnit reporter so the job surfaces failed assertions to GitHub.
Steps
- Export the collection and environment JSON from Postman into the repo.
- Install Newman with
npm install -g newman(or usenpx). - Run
newman run <collection> -e <env>and add-r junitfor a report. - Upload the JUnit XML so failures show in the run summary.
Workflow
.github/workflows/ci.yml
jobs:
api-tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '20'
- run: npm install -g newman
- run: >-
newman run collections/api.postman_collection.json
-e collections/ci.postman_environment.json
-r cli,junit --reporter-junit-export results/newman.xml
- uses: actions/upload-artifact@v4
if: always()
with:
name: newman-report
path: results/newman.xmlGotchas
- Newman exits non-zero on any failed assertion, which correctly fails the job.
- Override collection variables at run time with
--env-var name=valueinstead of baking secrets into the export.
Related guides
How to Set the API Base URL From Environment Variables in CIDrive the API base URL from an environment variable in GitHub Actions so one test suite runs unchanged agains…
How to Publish an API Test JUnit Report in CIEmit a JUnit XML report from any API test runner in GitHub Actions and publish it, so passed and failed reque…
How to Start the API and Wait for It Before Testing in CIStart your API in the background and block until it is ready with wait-on before API tests run in GitHub Acti…