Postman - Run Collections using Newman



To run Collections using Newman, we have to first launch the Postman application and click on the three dots available beside the Collection name. The details on how to create a Collection are discussed in detail in the Chapter − Postman Create Collections.

Run Collections

Follow the steps given below to run collections using Newman −

Step 1 − Click on Export.

Newman

Step 2 − Select the option Collection v2.1(recommended) from the EXPORT COLLECTION pop-up. Click on Export.

Newman1

Step 3 − Choose a location and then click on Save.

Step 4 − Next, we shall export the Environment. Click on the eye icon to the right of the No Environment dropdown.

Environment dropdown1

Step 5 − Click on the Edit link in the Globals section.

Globals section

Step 6MANAGE ENVIRONMENTS pop-up comes up. Enter URL for the VARIABLE field and https://www.tutorialspoint.com for INITIAL VALUE. Then, click on Download as JSON.

Finally, choose a preferred location and click on Save.

Location

Step 7 − Export the Environment to the same location where the Collection resides.

Step 8 − From the command-line move to the directory path where the Collection and the Environment is stored. Then, execute the command given below −

newman run <"file name">.

The file name should always be in inverted quotes; else it shall be taken as a directory name.

Common commandline arguments for Newman

The common command-line arguments for Newman are given below −

  • To execute a Collection in an Environment, the command is as follows −

newman run <name of Collection> -e <name of Environment>
  • To execute a Collection for a number of iterations, the command is as follows−

newman run <name of Collection> -n <iteration count>
  • To execute a Collection with data file, the command is as follows −

newman run <name of Collection> --data <name of file> -n <iteration count> -e <name of Environment>
  • Configure delay time in between requests, the command is as follows −

newman run <name of Collection> -d <time of delay>
Advertisements