ang
ang

Reputation: 1581

How to Test Same Endpoint Multiple Times with Postman Runner

I am trying to write an automated test Runner in Postman. I would like to test the same endpoint multiple times in a single run while changing the value of a parameter.

For example I would like to test

https://example.com/endpoint/{{item1}}
https://example.com/endpoint/{{item2}}
https://example.com/endpoint/{{item3}}

I can set a global variable on pass that in to run once with

let parameter = 'some value';
pm.globals.set("parameter", parameter);

How can I test an endpoint multiple times in one run?

Upvotes: 5

Views: 9685

Answers (3)

Danny Dainton
Danny Dainton

Reputation: 25881

Have you looked at using data files in Postman for this?

If you create a JSON file with the following values:

[
    {
        "item":"1"
    },
    {
        "item":"2"
    },
    {
        "item":"3"
    },
    {
        "item":"4"
    }
]

The file is just an array of objects, the keys would be the property that you reference in your requests, these would resolve to the value of the key. In the JSON file, each object is a single iteration so if you select 1, which is the default, it would run the request once using the value from the first object:

{ "item":"1" }

In your request url, within the collection, you would have something like https://example.com/endpoint/{{item}} - If you set the Iterations count to 4, it will run the same request but change the value to use the item variable each time.

The runner would look like this - If you're using the a JSON file, ensure that you manually select the file type. For some reason it doesn't always pick up this file type.

enter image description here

Upvotes: 1

codeblooded
codeblooded

Reputation: 350

Say, GET to https://google.com/q={{search}} and you have multiple search queries, (dog, chess, marvel, stackoverflow)

  • Create a collection in postman
  • Add a GET request to https://google.com/q={{search}} with necessary headers and hit Save
  • Create a CSV file with the header search and all search values under it
  • Hit the run button for the newly created collection
  • Set the Iterations field to the number of queries you have. In this example it is 4
  • Look for the field Data, select the created CSV file
  • Ensure the data is correctly being picked up by hitting the Preview button
  • Hit Run test
  • You can view the output in the Postman Console

postman runner

To open Postman Console Head to View in the application menu, and click on "Show Postman Console" or use the keyboard shortcut (CMD/CTRL + ALT + C) to open.

Upvotes: 0

A.Joly
A.Joly

Reputation: 2387

you shall use Postman's collection run facilities (have a look here) You can build a csv file, for example that will contain item1, item2, etc. then use it as your collection input. Launching the collection will call your test once for each parameter value ...

Upvotes: 0

Related Questions