Reputation: 1581
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
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.
Upvotes: 1
Reputation: 350
Say, GET to https://google.com/q={{search}}
and you have multiple search queries, (dog, chess, marvel, stackoverflow)
https://google.com/q={{search}}
with necessary headers and hit Save
search
and all search values under itIterations
field to the number of queries you have. In this example it is 4Data
, select the created CSV filePreview
buttonRun test
Postman Console
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