According to the official website of Postman: “Newman is a command-line Collection Runner for Postman”. That means that Newman is a CLI tool that allows you to run a Postman collection directly from the command line.
It is built with the idea in mind that you can easily integrate it with your continuous integration servers and build systems.
The first thing you need to do is install Node.js because Newman requires node.js and NPM. You can download and install Node.js on Linux, Windows and Mac OSX: https://nodejs.org/en/
To check if the installation of Node.js is successful, run the following command in the command line:
$ node -version
$ npm -version
If you see a version number, then you know that the installation of Node.js and NPM is successful.
After the installation of Node.js and NPM, you can install Newman by running the following command:
$ npm install -g newman
Installing Newman with –g on your system will allow you to run Newman from anywhere. To check if the installation of Newman was successful, run the following command in the command line:
$ newman -version
All you have to do now is export your postman collections to your pc. After that is done, you can use Newman to run tests from the terminal.
Postman can export your collections in two formats. The most used version is v2. This will save a JSON file on your system.
When you’re done, open the command line and navigate to the directory of the postman collection you just exported. Then use the Newman command (Change "yourPostmanCollection" to the name of your JSON file.):
$ newman run yourPostmanCollection.json
If everything went well, you will see output similar to the image below.
You will see a report at the end of the output. Isn't that cool?
Of course, we can also go further with Newman by creating a JUnit or HTML report. For example, run the Newman command again but include the reporters flag:
$ newman run --reporters html yourPostmanCollection.json
After execution, you will see an extra folder next to your postman collection containing the HTML report.
Newman offers many more options for running your collection than just -reports. You can get a list of all options by running:
$ newman –h
For example, this command will run the collection 10 times:
$ newman run yourPostmanCollection.json -n 10
There are many more options available, like integrating it into CI systems like Jenkins.
But that was it for now! I, therefore, hope that you will use Newman more often in your daily tasks.
Thanks for reading!