Working with options in Newman

To install and run a collection in Newman, you can refer this link.

Newman provides a rich set of options to customize a run. You can retrieve a list of options by running it with the -h flag.

newman run -h


Option Details -h, --help Output usage information -v, --version Output the version number

Basic setup

Option Details --folder [folderName] Specify a single folder to run from a collection. -e, --environment [file|URL] Specify a Postman environment as a JSON [file] -d, --iteration-data [file] Specify a data file to use either json or csv -g, --globals [file] Specify a Postman globals file as JSON [file] -n, --iteration-count [number] Define the number of iterations to run

Request options

Option Details --delay-request [number] Specify a delay (in ms) between requests [number] --timeout-request [number] Specify a request timeout (in ms) for a request


Option Details

--bail Stops the runner when a test case fails

--silent Disable terminal output

--color off Disable colored output

-k, --insecure Disable strict ssl

-x, --suppress-exit-code Continue running tests even after a failure,but exit with code=0

--ignore-redirects Disable automatic following of 3XX responses

--verboseShow Detailed information of collection run and each request sent

Let us try few commands in newman,

Run a collection with N number of iterations:

Use the -n option to set the number of iterations to run the collection.

newman run collectionName.json -n iterationCount

for example, we have executed our "deckofcards" collection in newman with 3 iterations. And we could see all the requests are executed thrice and reports are generated.

Run Collections with different set of data:

To provide different set of data to run your collection, such as environment variables or global variables for each iteration, you can use the -d to specify a JSON or CSV file.

newman run collectionName.json -d dataFileName.json

For example, In our collection "deckofcards" we use, two environment variables "deck_id" and "cards". Let us create a json file with following json, to pass those values and execute our collection.

    "deck_id": "b7n5shumtphi",
    "cards": "KS",    
    "count": "2"
    "deck_id": "55hyh0jxjd8z",
    "cards": "9H",    
    "count": "3"

We have created our data.json in the same path we have our exported collection.json

Now let's execute the command.

Automatically, the iteration is set to 2, as we sent two set of data.

you can also use csv file in the same way to read data.

To save the output to a file:

Json reported is used to store the output in an external file.

newman run collectionName.json --reporters cli,json --reporter-json-export output.json

Here we mentioned "json --reporter-json-export" to export our output file in json format. And "output.json" is the filename to save that report in the same path the collection is executed.

Happy Testing!!!

26 views0 comments

Recent Posts

See All

A string s is called good if there are no two different characters in s that have the same frequency. Given a string s, return the minimum number of characters you need to delete to make s good. The f

The numeric value of a lowercase character is defined as its position (1-indexed) in the alphabet, so the numeric value of a is 1, the numeric value of b is 2, the numeric value of c is 3, and so on.