Perform actions on the basis of iteration count in Collection Runner

I am doing some speed testing and I have the following issue:

  • I am running the collection and uploading the CSV file
  • I want to list an array that grabbed some data from all the calls but only after the last call

I managed to do it when I know the number of the rows in the CSV file but how can I achieve this when I don’t know the number of rows.

So in my case, I am grabbing the times into an array like this:

response_array = globals[‘response_times’] ? JSON.parse(globals[‘response_times’]) : []
postman.setGlobalVariable(“response_times”, JSON.stringify(response_array));

And in the end, I have this piece of code that lists the array in the console after all the rows finished:

if (response_array.length === 25) {
console.log("response_times are: " +pm.globals.get(“response_times”));

This works because I know that there are 25 rows in my CSV, but how can I achieve the same thing without knowing how many rows the CSV has.

Thank you for taking the time to read this or respond!

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

So, if you scroll down the docs -

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

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 object viz. which gives you the current iteration number.

So, to sum it up:

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

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

@sivcan Thank you for the fast reply. This is exactly what I needed! Best wishes!

1 Like

Most welcome!
Feel free to reach out in case you need any further help!