0
0
Postmantesting~15 mins

Delay between requests in Postman - Build an Automation Script

Choose your learning style9 modes available
Add delay between API requests in Postman collection
Preconditions (2)
Step 1: Open the Postman collection with multiple requests
Step 2: Select the first request in the collection
Step 3: Go to the Tests tab of the first request
Step 4: Add a script to pause execution for 3 seconds before the next request runs
Step 5: Save the script
Step 6: Run the collection using the Collection Runner
Step 7: Observe that there is a 3-second delay between the first and second request
✅ Expected Result: The collection runner pauses for 3 seconds between the first and second requests, delaying the next request execution as scripted.
Automation Requirements - Postman scripting (JavaScript)
Assertions Needed:
Verify that the delay script executes without errors
Verify that the delay causes a pause of approximately 3 seconds between requests
Best Practices:
Use pm.setNextRequest(null) to control request flow if needed
Use setTimeout or async/await with Promises for delay
Keep scripts simple and readable
Avoid hardcoding delays longer than necessary
Automated Solution
Postman
pm.test('Delay 3 seconds before next request', function(done) {
    setTimeout(() => {
        done();
    }, 3000);
});

This script is added in the Tests tab of the first request. It uses pm.test with a callback done to create an asynchronous test. Inside, setTimeout waits for 3000 milliseconds (3 seconds) before calling done(), which tells Postman to continue to the next request. This effectively adds a 3-second delay between requests during collection run.

This approach is simple and uses Postman's built-in asynchronous test handling to pause execution without blocking the UI.

Common Mistakes - 3 Pitfalls
Using synchronous loops or blocking code to create delay
Placing delay script in Pre-request Script tab instead of Tests tab
Not calling done() in asynchronous test, causing timeout
Bonus Challenge

Now add data-driven testing with 3 different delay durations (1s, 3s, 5s) for the delay between requests

Show Hint