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?
Practice
Solution
Step 1: Identify the official CLI tool for Postman collections
Newman is the official command line tool designed to run Postman collections.Step 2: Differentiate from other tools
npm is a package manager, curl is a general HTTP client, and postman-cli is not an official tool.Final Answer:
newman -> Option BQuick Check:
Postman CLI tool = newman [OK]
- Confusing npm with the CLI runner
- Using curl as a Postman collection runner
- Assuming postman-cli is official
test_collection.json using Newman?Solution
Step 1: Recall the Newman command to run collections
The correct command isnewman run <collection-file>.Step 2: Verify the options
Options like execute, start, or launch are not valid Newman commands.Final Answer:
newman run test_collection.json -> Option CQuick Check:
Command syntax = newman run [OK]
- Using 'execute' instead of 'run'
- Trying 'start' or 'launch' commands
- Omitting the 'run' keyword
newman run my_collection.json -e my_environment.json --delay-request 1000, what effect does the --delay-request 1000 option have?Solution
Step 1: Understand the --delay-request option
This option adds a delay between each request in the collection, measured in milliseconds.Step 2: Interpret the value 1000
1000 milliseconds equals 1 second delay between requests.Final Answer:
Delays each request by 1000 milliseconds between executions -> Option DQuick Check:
--delay-request = wait time between requests [OK]
- Confusing delay with timeout
- Thinking it repeats the collection
- Assuming it limits total requests
newman run collection.json -e env.json --reporters cli,html but get an error saying Unknown reporter: html. What is the most likely cause?Solution
Step 1: Analyze the error message
The error states 'Unknown reporter: html', meaning Newman does not recognize the 'html' reporter.Step 2: Understand reporter support
Newman supports some reporters by default; others require installation or are unsupported.Final Answer:
The HTML reporter is not installed or supported by Newman -> Option AQuick Check:
Unknown reporter means unsupported or missing plugin [OK]
- Blaming environment or collection files
- Assuming CLI reporter conflicts
- Ignoring reporter installation requirements
data.csv. Which Newman command correctly achieves this?Solution
Step 1: Identify the option for data files in Newman
The-dor--iteration-dataoption is used to specify a data file for iteration.Step 2: Differentiate environment and data options
-eor--envis for environment files, not data files.Final Answer:
newman run collection.json -d data.csv -> Option AQuick Check:
Use -d for data files in Newman [OK]
- Using -e or --env for data files
- Using --data, an invalid flag
- Confusing environment and data files
Ready to prove it?
Pass the test and this pattern moves unknown
