Running a Postman collection from the command prompt can be accomplished using Newman, which is a command-line collection runner for Postman. Here's a step-by-step guide on how to do it:
Prerequisites
Install Node.js: Ensure Node.js is installed on your machine. You can download it from Node.js official website. https://nodejs.org/en
Install Newman: Newman is a command-line collection runner for Postman. Install it globally using npm:
shnpm install -g newman
Export Your Postman Collection
Open Postman: Launch Postman and open the collection you want to run.
Export Collection:
- Click on the ellipsis (...) next to the collection name.
- Select "Export".
- Choose "Collection v2.1" and click "Export".
- Save the exported JSON file to your desired location.
Run the Collection Using Newman
Open Command Prompt: Open the command prompt or terminal.
Run the Collection: Use the following command to run the collection with Newman:
shnewman run path/to/your/collection.json
Additional Options
Newman provides various options to customize the execution of your collection:
Specify Environment Variables: If your collection requires environment variables, you can export your Postman environment and include it in the command:
shnewman run path/to/your/collection.json -e path/to/your/environment.json
Data File: If you want to run the collection with a data file (for data-driven testing), use the
-d
flag:shnewman run path/to/your/collection.json -d path/to/your/datafile.json
Reporters: Generate different types of reports (e.g., HTML, JSON) using the
-r
flag:shnewman run path/to/your/collection.json -r html
Iteration Count: Specify the number of iterations to run the collection:
shnewman run path/to/your/collection.json -n 10
Example Command
Here’s an example command that includes the collection, environment variables, data file, and generates an HTML report:
shnewman run path/to/your/collection.json -e path/to/your/environment.json -d path/to/your/datafile.json -r html
Summary
By using Newman, you can easily run your Postman collections from the command prompt, enabling automated testing and integration into CI/CD pipelines. The flexibility provided by Newman’s options allows you to customize the execution to fit your specific needs.
==========================================================
when you run the command 'newman' in commandprompt The error 'newman' is not recognized as an internal or external command, operable program or batch file
Solution for above error is as below :
The error 'newman' is not recognized as an internal or external command, operable program or batch file
indicates that the system cannot find the newman
command. This typically happens because Newman
is not installed globally or the global npm bin directory is not in your system's PATH.
Here are the steps to resolve this issue:
Step 1: Verify Node.js and npm Installation
Ensure Node.js and npm are installed and properly set up on your system. You can verify this by running the following commands in the command prompt:
shnode -v npm -v
If these commands do not return a version number, you need to install Node.js from the official website.
Step 2: Install Newman Globally
Install Newman globally using npm:
shnpm install -g newman
Step 3: Verify Newman Installation
After installing, verify that Newman is installed correctly by running:
shnewman -v
This should return the version number of Newman.
Step 4: Update System PATH
If you still encounter the issue, it might be because the npm global bin directory is not in your system's PATH. To add it:
Locate npm global bin directory: Run the following command to find out where npm installs global packages:
shnpm config get prefix
This will return a directory path (e.g.,
C:\Users\YourUsername\AppData\Roaming\npm
).Add the npm global bin directory to PATH:
- Right-click on
This PC
orComputer
on your desktop or in File Explorer, and selectProperties
. - Click on
Advanced system settings
. - Click on the
Environment Variables
button. - In the
System variables
section, find thePath
variable, select it, and clickEdit
. - Add the npm global bin directory (e.g.,
C:\Users\YourUsername\AppData\Roaming\npm
) to the list. Each entry should be separated by a semicolon (;
). - Click
OK
to close all dialog boxes.
- Right-click on
Restart Command Prompt: After updating the PATH, restart your command prompt to apply the changes.
Step 5: Run Newman Command
Navigate to your project directory and run the Newman command again:
shcd C:\javaprograms\APITestingINfo\NewManTests
newman run PostmanAPIMay162024.postman_collection.json -e pmqaMay1624.postman_environment.json
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.