5

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?

Matthew
  • 1,461
  • 3
  • 23
  • 49

3 Answers3

1

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

Carasel
  • 2,740
  • 5
  • 32
  • 51
Danny Dainton
  • 23,069
  • 6
  • 67
  • 80
  • When I tried this it ran an auth endpoint at the beginning of each iteration, and didn't seem to pass the auth token into subsequent requests. Does the data file override any other variable mappings? – Matthew Oct 02 '18 at 12:55
  • e.g. `auth --> item, auth --> item`, instead of `auth --> item --> item`. – Matthew Oct 02 '18 at 12:56
0

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 ...

A.Joly
  • 2,317
  • 2
  • 20
  • 25
0

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.

codeblooded
  • 320
  • 1
  • 9