Is there a way to access the iteration number in Postman REST Client?

24.4k Views Asked by At

I'm using postman for API testing. I'm running a large number of tests and I want to print the iteration number to the console on some of them. Is there a way to get the iteration number as an environment-like variable?

5

There are 5 best solutions below

0
On BEST ANSWER

It is possible now! You can access the iteration variable, in the same way you access other variables like responseBody.

1
On

I don't know if there is an internal way to get the iteration number but I believe you should be able to track this number through code yourself. Here's a quick code snippet:

var value = environment.count;
value++;
postman.setEnvironmentVariable("count", value);

If you put this in the pre-request editor or the test editor of a collection that you are sure will run once per iteration it will effectively track the iteration count.

0
On

I got there like this:

const count = pm.info.iteration+1

console.log("======== LITERATION "+count+" ========");

4
On

According to Postman API Reference, pm.info.iteration - is the value of the current iteration being run.

Example:

console.log(pm.info.iteration);
0
On

You can get the iteration number with

pm.info.iteration:Number

Is the value of the current iteration being run.

Postman Sandbox API reference