Perform actions on the basis of iteration count in Collection Runner

Hey @gherghinoiu, the good news is that it’s solvable!

So, if you scroll down the docs - https://www.getpostman.com/docs/v6/postman/scripts/postman_sandbox_api_reference

You’ll see that in the pm.info object, there’s a property called as iterationCount which is the total number of iterations that are scheduled to run.

Now,
Total number of iterations === Number of rows in your CSV File

Also, instead of using the response_array.length you can use another property of the pm.info object viz. pm.info.iteration which gives you the current iteration number.

So, to sum it up:

In your test-script you can put the following code snippet:

// Since, pm.info.iteration starts from 0
// Thus, we'll check if iteration === iterationCount - 1
if (pm.info.iteration === pm.info.iterationCount - 1) {
    console.log(`response_times are: ${pm.globals.get('response_times')}`);
}
2 Likes