How to add a pause between two requests in POSTMAN

I have a collection of requests in POSTMAN. I wanted to add a pause between the two requests, but I could not find a way to do this by reading their documents. Any idea?

UPDATE I just wanted to pause after one request, and not after each request in the collection.

+10
source share
7 answers

If someone is still looking for this - you can add a delay after / to 1 of the many tests in the collection that you can use:

setTimeout(function(){}, [number]); 

where the "number" is milliseconds. If it is added to the "Tests", it will be executed after sending the request. If it is added in the "tests before the request", it will be executed before sending the request.

+7
source

I know two possible ways to do this.

Method I

Run your query as a collection. ( https://www.getpostman.com/docs/collections ) Use Newman (the command-line postman collector) to launch your collection with the --delay flag. The input delay value is in milliseconds.

Method II

This is a good hack that I found here https://github.com/postmanlabs/postman-app-support/issues/1038 . You can add a delay function to your test script in Postman.

+5
source

Using busy wait Javascript is a good hack, but it makes your processor hot and the application is not responding. I understood this solution using the postman echo.

Assuming you want to add a long delay between Request_A and Request_B.

First, in the Request_A test script, set env var to mark the beginning.

environment.delayTimerStart = new Date();

Then create a GET request at creation (here it is called โ€œDelay 10 sโ€). It does a GET at https://postman-echo.com/delay/10 (returns in 10 seconds)

In your test case add

 var curDate = new Date(); if (curDate - environment.delayTimerStart < delay_time_in_sec*1000) { postman.setNextRequest('Delay 10s'); } else { postman.setNextRequest("Request_B"); } 

This way you can add a delay of any length.

Note: 10 seconds is the maximum value that the postman echo accepts. If you just need a little delay, just GET https://postman-echo.com/delay/[1~10] .

+1
source

I prefer to use the Postman Echo delay endpoint online service (docs here ). Just create a request that uses this service and call it between two other requests that you want to add a delay between.

If you want to check the status of something before continuing, you can use postman.setNextRequest() in the Tests request for the loop until something is complete. Just follow these steps:

1) Create a collection structured as:

  • 10 second delay
  • Status check
  • Continue processing

2) In the request Status Check Tests:

 if(responseBody.has("Success")) //or any other success condition { postman.setNextRequest('Continue Processing'); tests["Success found"] = true; } else { postman.setNextRequest('Delay For 10 Seconds'); tests["No success found"] = true; } 
+1
source

If you have a standalone Postman application (supports ES7), and you are going to test only on Postman, and not on Newman (which does not support ES7), then you can do something similar in the preliminary request script for the request I want to postpone:

 function foo() { return (new Promise((resolve, reject) => { setTimeout(() => { resolve("done!"); // passing argument is optional, can just use resolve() }, 10000) // specify the delay time in ms here.. })) } async function waitForMe() { await foo().then((val) => { console.log(val); // not required, you can just do an await without then }) } waitForMe(); 
+1
source

view current documentation if you are using Postman Runner

Delay

This is the interval (in ms) between each request in the collection run.

https://www.getpostman.com/docs/postman/collection_runs/starting_a_collection_run

and if you use newman

--delay-request [number] Specify a delay (in ms) between requests [number]

https://www.getpostman.com/docs/postman/collection_runs/command_line_integration_with_newman

0
source

You can use the setTimeout JavaScript method. This ensures that your method is executed after the specified delay.

enter image description here

  setTimeout(checkStatusCode, 500); function checkStatusCode() { pm.sendRequest('https://postman-echo.com/get', function (err, res) { tests['status code should be 200']= res.code ===200; }); } 
0
source

Source: https://habr.com/ru/post/1259436/


All Articles