How to add a pause between 2 requests in POSTMAN

2020-05-22 10:07发布

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.

9条回答
We Are One
2楼-- · 2020-05-22 10:44

If you have the standalone Postman App (supports ES7) and you are intending to test only on Postman, not on newman(which doesn't support ES7), then you can have something like this in the Pre-Request script of the Request you want to delay:

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();
查看更多
看我几分像从前
3楼-- · 2020-05-22 10:51

Just simple example, I'm sure you will be understand.

setTimeout(() => {}, 15000); 

15000 it's a value in miliseconds

查看更多
Juvenile、少年°
4楼-- · 2020-05-22 10:57

I prefer to use an online service Postman Echo's delay endpoint (docs are here). Simply create a request that uses this service and call it between the two other requests you wish to add a delay between.

If you want to check the status of something before continuing, you can use postman.setNextRequest() in the Tests of a request to loop until something has been completed. Simply do the following:

1) Create a collection structured as:

  • Delay For 10 Seconds
  • Status Check
  • Continue Processing

2) In the Status Check request 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;
}
查看更多
登录 后发表回答