postman-project/ ├── collections/ │ └── my-collection.json # Postman collection JSON file ├── environments/ │ └── dev-environment.json # Environment variables for dev ├── reports/ │ └── test-report.html # Generated test reports ├── scripts/ │ └── pre-request-scripts.js # Optional helper scripts ├── newman-config.json # Newman CLI configuration file └── package.json # Node.js project config (if using npm)
Running collections via CLI in Postman - Framework Patterns
- Collections: JSON files defining API requests and tests.
- Environments: JSON files holding environment-specific variables.
- Scripts: Optional JavaScript files for pre-request or test scripts.
- Configuration: Newman CLI config file to define run options.
- Reports: Output folder for test run reports (HTML, JSON, etc.).
Use separate environment JSON files for different setups (dev, staging, prod). Pass these to Newman CLI with --environment option.
Use a newman-config.json file or npm scripts to store common CLI options like reporters, iteration count, or timeout.
Store sensitive data in environment files and avoid committing secrets to version control.
Example CLI command:
newman run collections/my-collection.json --environment environments/dev-environment.json --reporters cli,html --reporter-html-export reports/test-report.html
Newman supports multiple reporters: CLI, HTML, JSON, JUnit XML.
Generate HTML or JUnit reports for easy viewing and integration with CI tools like Jenkins, GitHub Actions, or GitLab CI.
Example: Use --reporters cli,junit and --reporter-junit-export reports/results.xml to produce JUnit XML for CI pipelines.
Automate collection runs in CI by adding Newman commands in pipeline scripts.
- Keep collections and environments in separate folders for clarity.
- Use environment variables to avoid hardcoding URLs or credentials.
- Use Newman CLI options or config files to standardize test runs.
- Generate readable reports and integrate them into CI pipelines.
- Keep sensitive data out of version control by using environment files and .gitignore.
Where would you add a new environment file for testing the staging server in this folder structure?