How to run postman requests/tests from command line (Newman)

Mousume Haque
3 min readJan 26, 2020

Newman is a command line collection runner for Postman.

Let’s learn about Newman and how to run the postman collection using a command line tool with global variables and environment.

Step 1: Check if node.js is already installed or not

a) Open your cmd from your machine

b) Type: 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 your system yet.

c) You can also try with: npm -v

npm is node package manager which is used to installed packages over node.

If found: ‘npm’ is not recognized as an internal or external command, operable program or batch file

So again it’s not found node in the system.

Step 2: Install node.js

Why we have to install node.js ? This question may come into your mind. Because Newman is node.js program and to get newman we have to first install node.js

Official site: https://nodejs.org/en/download/

So go to the download link and install node.js

During installation no need to check “Automatically install the necessary tools”.

Now again to check, Type: node -v

And you will see the version of node.

Also Type: npm -v

And you will get the version of npm.

Step 3: Install Newman

Command: $ 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.

You can also check physically on your system whether it is installed or not.

Go to: C drive > Users > AppData > Roaming > npm folder > node_modules > newman folder > newman & newman.cmd

Step 4: Export your Postman API collection as json file

Step 5: On cmd go to that location of collection json file

Command: cd (space)(location)

$ cd C:\Users\Mousume\Desktop\Postman_Collections>

Step 6: Run the API collection

Command: newman run (space)(collection name)

$ newman run Automation_Test.postman_collection.json>

Hit enter and here you go-

You will find, it was running everything what is inside your collection. There is GET request, test-scripts, POST request, prerequest-scripts.

And 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.

Step 8: With Environment and Global Variables. (use -e, -g)

Command: $ newman run Automation_Test.postman_collection.json -e enviroment.json -g global.json

Step 7: To get all newman commands/options

Command: $ newman run -h

--

--

Mousume Haque

Innovative and professional Software Testing & Quality Assurance Engineer with 8+ years hands on experience in testing of web applications & mobile application.