Newman is a command-line collection runner for Postman. A postman collection can run and be tested directly from the command-line. The collection runs in the same way it is executed, inside the collection runner in postman. Newman can also be used to generate reports.
How it works
- Ensure you have Nodejs installed on your laptop: Check your environment variables and make sure the path contains C:\Program Files\nodejs; and then, go to command prompt and type npm -version in your command prompt then press enter
If you don’t have, no need to panic! Head to https://nodejs.org/en/download/ and download the appropriate version for your PC.
- Install Newman: In the command prompt type, this command “npm install -g newman”, press enter and wait patiently till the installation is complete.
- Install Newman HTML reporter: In the command prompt, type this command “npm install -g newman -reporter-htmlextra”, press enter and wait.
- Export both your collection and environment from Postman to an empty folder on your laptop.
- Run the test and generate a test report
– Copy the path of the folder containing the collection and environment exported from postman
– On the command prompt type “cd”, then paste the copied path and press enter
– To run the test, type “newman run collection_name -e environment_name” and press enter. The “collection_name” and “environment_name” is the name your collection and environment are saved as. In this example, they are saved as “collection.json” and “environment.json” respectively.
– To generate the HTML report, type “newman run collection_name -e environment_name -r htmlextra”
– Now check the folder containing the collection and environment; a new folder named newman would have been automatically created
– Open the newman folder created and open the content to view the html report generated
There you have it, we have successfully run and generated our postman test result using Newman in 5 simple steps.