Complete the code to add a delay of 2 seconds between requests in Postman using JavaScript.
setTimeout(function() { pm.sendRequest(request, function (err, res) { console.log(res); }); }, [1]);The setTimeout function expects the delay in milliseconds. 2000 milliseconds equals 2 seconds.
Complete the code to pause the test script for 1 second before sending the next request in Postman.
pm.test('Pause for 1 second', function(done) { setTimeout(done, [1]); });
The done callback is called after the delay. 1000 milliseconds equals 1 second.
Fix the error in the code to correctly delay the request by 3 seconds in Postman.
setTimeout(() => pm.sendRequest(request, (err, res) => { console.log(res); }), [1]);The delay must be in milliseconds. 3000 milliseconds equals 3 seconds.
Fill both blanks to create a function that delays a request by a given number of seconds in Postman.
function delayRequest(seconds) { setTimeout(() => pm.sendRequest(request, (err, res) => { console.log(res); }), [1] * [2]); }The delay in setTimeout is milliseconds, so multiply seconds by 1000.
Fill all three blanks to create a reusable delay function and use it to delay a request by 5 seconds in Postman.
function [1](s) { return new Promise(resolve => setTimeout(resolve, s * [2])); } async function sendDelayedRequest() { await [3](5); pm.sendRequest(request, (err, res) => { console.log(res); }); }
The function delay returns a promise that resolves after the given seconds multiplied by 1000 milliseconds. The async function awaits this delay before sending the request.