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?
Is there a way to access the iteration number in Postman REST Client?
24.4k Views Asked by toshiomagic At
5
There are 5 best solutions below
1

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

I got there like this:
const count = pm.info.iteration+1
console.log("======== LITERATION "+count+" ========");
4

According to Postman API Reference, pm.info.iteration - is the value of the current iteration being run.
Example:
console.log(pm.info.iteration);
It is possible now! You can access the
iteration
variable, in the same way you access other variables likeresponseBody
.