0
0
Postmantesting~5 mins

Iteration count in Postman

Choose your learning style9 modes available
Introduction

Iteration count tells how many times a test runs in a loop. It helps test many cases without repeating code.

You want to run the same API test with different data sets.
You need to check if a service works well after many repeated calls.
You want to simulate multiple users hitting the API one after another.
You want to test how your system behaves over time with repeated requests.
Syntax
Postman
pm.info.iteration

This is a read-only variable in Postman scripts.

It starts from 0 for the first iteration and increases by 1 each time.

Examples
Prints the current iteration number in the Postman console.
Postman
console.log(pm.info.iteration);
Checks if this is the first iteration and logs a message accordingly.
Postman
if (pm.info.iteration === 0) {
    console.log('First run');
} else {
    console.log('Run number ' + pm.info.iteration);
}
Sample Program

This test checks that the iteration count is a number and not negative. It also prints the current iteration number.

Postman
pm.test('Check iteration count', function () {
    pm.expect(pm.info.iteration).to.be.a('number');
    pm.expect(pm.info.iteration).to.be.at.least(0);
});

console.log(`Current iteration: ${pm.info.iteration}`);
OutputSuccess
Important Notes

Iteration count starts at 0, so the first run is iteration 0.

You can use iteration count to pick data from an array for data-driven testing.

Remember to set the number of iterations in the Postman Collection Runner before running tests.

Summary

Iteration count helps run tests multiple times automatically.

It starts at zero and increases by one each run.

Use it to test different data or repeated calls easily.