Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add a pause between 2 requests in POSTMAN

I have a collection of requests in POSTMAN. I wanted to add a pause between 2 requests but I couldn't find a way to do so from reading their docs. Any idea?

UPDATE I only wanted to put a pause after one request instead of after every request in the collection.

like image 936
RoundOutTooSoon Avatar asked Nov 08 '16 02:11

RoundOutTooSoon


People also ask

What is delay in Postman runner?

You can also run collections multiple times against different data sets to build workflows. Delay - An interval delay in milliseconds between each request.

How do I set timeout on Postman?

Request Timeout in ms - Enter how long (in milliseconds) Postman will wait for a response before timing out. If you enter 0, Postman will wait for a response forever. Max response size in MB - Enter the largest response size (in megabytes) that Postman will download.

How do you execute the same post multiple times in Postman?

If you have workflows where you need to issue a single request n number of times, you would want to use postman. setNextRequest() , with the argument set to the name of the current request. This will cause Postman to execute the same request again.


2 Answers

In case someone is still looking for this - You can add delay after/before 1 of many test in a collection you can use:

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

where 'number' is the milliseconds. If it's added at 'Tests' it will be executed after request is send. If it's added at 'pre-request tests' it will be executed before request is send.

like image 127
Ivo Avatar answered Oct 07 '22 23:10

Ivo


Using javascript's busy wait is a good hack but it makes your CPU hot and the app unresponsive. I figured out this solution using postman-echo.

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

First, in Request_A's test script set up an env var to mark the start.

environment.delayTimerStart = new Date();

Then, create a GET request in the creation (here called 'Delay 10s'). It makes a GET on https://postman-echo.com/delay/10 (It returns after 10s)

In its test script, add

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

In this way you can add a delay of any length.

Note: 10 sec is the maxium value that postman-echo accepts. If you just need a short delay, simply GET https://postman-echo.com/delay/[1~10].

like image 20
Siyu Avatar answered Oct 07 '22 22:10

Siyu