Sometimes you need to wait a bit between sending requests to avoid overloading the server or to simulate real user behavior.
Delay between requests in Postman
Start learning this pattern below
Jump into concepts and practice - no test required
// Use setTimeout in the 'Tests' tab to delay the next request setTimeout(() => { postman.setNextRequest('Next Request Name'); }, delayInMilliseconds);
Replace 'Next Request Name' with the exact name of the next request in your collection.
delayInMilliseconds is the number of milliseconds to wait before sending the next request.
// Wait 2 seconds before next request setTimeout(() => { postman.setNextRequest('Get User Data'); }, 2000);
// Wait 5 seconds before next request setTimeout(() => { postman.setNextRequest('Update Profile'); }, 5000);
This script waits 3 seconds after the first request finishes, then moves to 'Second Request'. The console logs show the delay and transition.
// In the 'Tests' tab of the first request console.log('Starting delay before next request'); setTimeout(() => { postman.setNextRequest('Second Request'); console.log('Moving to Second Request after delay'); }, 3000);
Postman runs scripts quickly, so setTimeout is needed to create a real delay.
Make sure the next request name matches exactly, including spaces and case.
Delays help avoid hitting rate limits or simulate real user pacing.
Use setTimeout with postman.setNextRequest to delay between requests.
Delay time is in milliseconds (1000 ms = 1 second).
Delays help test realistic scenarios and avoid server overload.
Practice
Solution
Step 1: Understand delay usage in Postman
Delays are used to mimic real user wait times and prevent sending too many requests too fast.Step 2: Identify the correct purpose
Speeding up tests or skipping requests are not related to delays; delays help simulate real scenarios and protect servers.Final Answer:
To simulate real user behavior and avoid server overload -> Option DQuick Check:
Delay purpose = simulate real use and avoid overload [OK]
- Thinking delays speed up tests
- Confusing delay with skipping requests
- Assuming delay changes request data
Solution
Step 1: Recall correct setTimeout syntax
setTimeout takes a function and delay in milliseconds: setTimeout(function, delay).Step 2: Check usage with postman.setNextRequest
postman.setNextRequest must be called inside a function passed to setTimeout to delay execution.Final Answer:
setTimeout(() => postman.setNextRequest('Request2'), 2000); -> Option CQuick Check:
Use setTimeout with function and delay [OK]
- Passing setNextRequest call directly to setTimeout
- Using non-existent delay function
- Trying to pass delay as second argument to setNextRequest
setTimeout(() => postman.setNextRequest('Login'), 3000);
console.log('Request scheduled');Solution
Step 1: Understand setTimeout behavior
setTimeout delays the function call (postman.setNextRequest) by 3000 ms, but console.log runs immediately.Step 2: Determine order of execution
console.log('Request scheduled') runs first; after 3 seconds, the 'Login' request is set to run next.Final Answer:
'Request scheduled' logs immediately, and 'Login' request runs after 3 seconds -> Option BQuick Check:
console.log immediate, setNextRequest delayed [OK]
- Assuming setNextRequest runs immediately
- Thinking console.log waits for delay
- Confusing order of asynchronous calls
setTimeout(postman.setNextRequest('NextRequest'), 1000);Solution
Step 1: Analyze setTimeout usage
setTimeout expects a function as first argument, but here postman.setNextRequest is called immediately.Step 2: Correct usage for delay
Wrap postman.setNextRequest call inside a function (e.g., arrow function) to delay execution properly.Final Answer:
postman.setNextRequest should be inside a function passed to setTimeout -> Option AQuick Check:
Pass function to setTimeout, not direct call [OK]
- Passing direct call instead of function to setTimeout
- Confusing milliseconds with seconds
- Believing setTimeout is unsupported in Postman
Solution
Step 1: Understand sequential delays
Each request must be delayed before triggering the next; nested setTimeout calls create sequential delays.Step 2: Analyze options
setTimeout(() => { postman.setNextRequest('Request2'); setTimeout(() => postman.setNextRequest('Request3'), 1000); }, 1000); nests setTimeout calls to delay Request2 by 1s, then Request3 by another 1s, correctly sequencing requests with delays.Final Answer:
setTimeout(() => { postman.setNextRequest('Request2'); setTimeout(() => postman.setNextRequest('Request3'), 1000); }, 1000); -> Option AQuick Check:
Nested setTimeouts create sequential delays [OK]
- Calling setNextRequest multiple times without delay
- Not nesting delays causing immediate requests
- Assuming one setTimeout delays all requests
