In this tutorial, we will run the Postman requests from the command line. Newman is a command line collection runner for Postman.
Table of Contents
What is Newman?
Newman enables you to run and test a Postman Collection directly from the command line. It’s built with extensibility in mind so that you can integrate it with your continuous integration (CI) servers and build systems.
Let’s learn about Newman and how to run the Postman collection using a command line.
Implementation Steps
Step 1: Check if node.js is already installed or not
Open your cmd from your machine
node -v
If found: ‘node’ is not recognized as an internal or external command, operable program, or batch file
That means node.js is not installed on your system yet.
Step 2: Check if npm is already installed or not
npm is node package manager which is used to installed packages over node.
npm -v
‘npm’ is not recognized as an internal or external command, operable program or batch file message means that node is not found in the system.
Step 3: Install node.js
Newman is node.js program and to get newman we have to first install node.js
Official site: https://nodejs.org/en/download/
Depending upon the system requirement, select and download 32-bit or 64-bit for Window or macOS operating system Node.js installer.
Once the installer finishes downloading, launch it. Open the downloads link in your browser and click the file. Or, browse to the location where you have saved the file and double-click it to launch. Click the “Next” button.
Select the option “I accept the terms in the License Agreement” and click the “Next” button.
The installer will prompt you for the installation location. Leave the default location, unless you have a specific need to install it somewhere else. Click the “Next” button.
This screen shows that npm package manager is also getting installed. Click the “Next” button.
Select the “Next” button.
Click on the “Install” button.
This screen shows that installation is in progress.
Click the “Finish” button to end the installation process.
Step 4: Check if node.js and npm are successfully installed
Close the cmd prompt and reopen the cmd prompt. Type node-v command and see if the version is displayed or not. The below image shows that node.js of version 18.17 is installed on the machine.
Type npm-v command and see if the version is displayed or not. The below image shows that npm of version 9.6.7 is installed on the machine.
Step 5: Install Newman
npm install -g newman
It will get Newman then install in your system. It will take couple of second.
After finishing the installation you can see it has added all the packages from contributors.
Step 6: Export the already created Postman tests
Export your Postman API collection as json file
This screen provides the option to export the json file as Collection v2 or Collection v2.1 and click on the “Export” button.
On cmd go to that location of collection json file
cd C:\Users\Vibha\Desktop\Automation\Postman
Step 7: Run the API collection through command line
newman run API_Testing.json
The output of the above command is shown below. There is a log of entire over all summary showing iterations, requests, test-scripts, prerequest-scripts, assertions, total run duration, total data received, average response time and in case of any failure we get the details of failure and all.
Congratulations!! We have run the Postman tests through command line. I hope this tutorial is useful to you.