Author : Geetu Sadana
Newman is a command line Collection Runner for Postman. It allows you to run and test a Postman Collection directly from the command line. It is built with extensibility in mind so that we can easily integrate it with continuous integration servers and build systems.
Once we have set up all our collections and written tests for them, it may be tedious to go through them one by one and click send in postman to see if a given collection test passes. This is where Newman comes in. All we need to do is export collection, then use Newman to run the tests from your terminal.
- The first step is to export collection via Clicking on the Menu icon for API collection and selecting export.
- Select version 2, and click on “Export”
- Save the JSON file in a location you can access with your terminal
- Install Newman CLI, then navigate to path where you saved the collection.
Command for Installing newman
npm install -g newman
Make sure to have npm installed on system first.
Once we are in the directory, run
newman run <collection_name.json>
Replace the collection_name with the name of the collection.
To provide a different set of data, i.e. variables for each iteration, we can use the -d to specify a JSON or CSV file.
newman run <collection_name.json> -d <CSVfile>
Command to extract Report in HTML format
Command would be
- npm install -g newman-reporter-htmlextra
run below command
- newman run <collection_name.json> -r htmlextra — Reporters htmlextra — darkTheme
Report will be generated in HTML format as below.
Command to have both CMD logs and HTML Report
newman run <collection_name.json> -r cli, htmlextra — Reporters htmlextra — darkTheme
Command to export report at specific location
newman run <collection_name.json> -r htmlextra — Reporters htmlextra- export “newman/foldername” — Reporters htmlextra — darkTheme
Newman summary report overview
htmlextrareport generates detailed reports. This reporter comes with a dashboard style summary landing page and a set of different tabs which contain the detailed request information. This makes it possible to have an overview of all test runs, and share Postman API test reports that can be understood by anyone.
The salient features of the Reporter include:
- Separate views for summary and all requests. There’s also a separate tab to just view the failed requests.
- It also contains console logs.
- Lots of color-coding to distinguish failures and success just by looking at the report.
- More interactive with tabbed views as well as expand/collapse options for request details.
- Complete request and response payloads, time and size and headers of each test.
- Assertion details under test information.
Other blogs in this series -
Advanced Features of Postman :
Postman is a powerful tool used to test web services. It offers a simple user-friendly interface. List of various advanced features of postman
- Collection runner
- Data Driven Testing in collection
- Global Variables
To learn more about these features, refer here.
Apache Drill for DB Connection in Postman :
Looking into building up an end to end solution for API testing. Postman being a rest client not a DB client was a big challenge. So we need a Middle ware to communicate from Postman to DB directly. So this can be resolved using the open source SQL query engine Apache Drill. To learn more about this, refer here.
Codeless API Automation and Monitoring System using Postman :
This blog describes the technique to automate APIs using Postman instead of Rest Assured and describes the advantages of using Postman over Rest Assured. To read more about this, refer here .