2

I am writing a new API and want to be able to see how it fairs when hit with n requests.

I have tried to setup environment variables and use the runner tool within Postman to no avail.

End goal is to run it n times, where I pass in the value of [n] into the body so I can audit (the value of that field is stored in database).

I have setup 2 environment variables

company=Bulk API Test
requestcount=0

My pre-request script is

let requestCount = +postman.getEnvironmentVariable("requestcount");
if(!requestCount)
{
    requestCount = 0;
}

requestCount++;
postman.setEnvironmentVariable("requestcount", requestCount);

Which should update the environment variable requestcount to +1 each time.

My test script is

var currentCount = +postman.getEnvironmentVariable("requestcount");
if(currentCount < 5) // want it to run 5 times
{
    postman.setNextRequest("https://snipped");
}
else
{
    postman.setNextRequest(null);
}

When I run it through the runner it takes much longer than a non-runner execution and the result is the API was only hit once.

andrewb
  • 2,995
  • 7
  • 54
  • 95

1 Answers1

1

If your API Call is always the same, try just using the iteration-count of the postman runner. Just enter there e.g. 5. And your collection will be repeated 5 times.

enter image description here

Cou cann access the iteration over the following property:

pm.info.iteration

to find out, which iteration it was.

If you still need to icrement variables make sure, that they parsed as integers.

var currentCount =+ parseInt(postman.getEnvironmentVariable("requestcount"));

To be honest: The best way for this benchmarking test would be to use a load-test tool e.g. Loadrunner instead of Postman.

DieGraueEminenz
  • 830
  • 2
  • 8
  • 18
  • Yes but I need a variable to change (increment by 1) between each run/iteration – andrewb May 28 '19 at 15:09
  • @adrewb i addad also a hint for parsing of integers. You must parse your value to an integer if you load it from the env or globals. This is necessary, because postman stores everything as string in the env and global vars. – DieGraueEminenz May 28 '19 at 16:07