0
0
Postmantesting~15 mins

Iteration count in Postman - Build an Automation Script

Choose your learning style9 modes available
Verify iteration count in Postman collection runner
Preconditions (2)
Step 1: Open the Postman collection runner
Step 2: Select the collection to run
Step 3: Set the iteration count to 3
Step 4: Start the run
Step 5: Observe the number of times the request is sent
✅ Expected Result: The request is executed exactly 3 times as per the iteration count set
Automation Requirements - Postman test scripts
Assertions Needed:
Verify that the current iteration number is less than the total iteration count
Verify that the request is executed the expected number of times
Best Practices:
Use pm.info.iteration to get the current iteration number
Use pm.test to write assertions
Keep test scripts simple and clear
Automated Solution
Postman
pm.test('Iteration count is within expected range', function () {
    pm.expect(pm.info.iteration).to.be.below(3);
});

This test script uses pm.info.iteration to get the current iteration number, which starts from 0. The assertion checks that the iteration number is less than 3, meaning the test runs exactly 3 times (0, 1, 2). This confirms the iteration count is respected during the collection run.

Using pm.test defines a test with a clear name, and pm.expect is used for assertion following Postman best practices.

Common Mistakes - 3 Pitfalls
Using pm.info.iteration without considering zero-based index
Not setting iteration count in collection runner before running tests
Writing complex logic inside test scripts to count iterations
Bonus Challenge

Now add data-driven testing with 3 different data sets and verify iteration count for each

Show Hint