newman
newman copied to clipboard
dynamic/variable delay between requests
First off, thanks for this package! It's greatly helped my integration testing.
What would make my life even better would be able to specify the delay between specific requests, instead of the the global delay options.delayRequest
where the delay is the same between all requests.
The reason is I need to have a delay of ~30secs after some requests (that initiate a long async task), and the following request that depends on the results of that long async task. I could set options.delayRequest = 30
, but then all requests in the run will have 30sec delays between them, but only a few requests need the 30sec delay.
Maybe there's already a way to do this?
For each request, if you want to wait before sending a request, add this to the pre-request script.
setTimeout(function () {
console.log("executed delay for 1000 ms");
}, 1000); // delay in 1000 ms
Set your delay to desired value in ms by setting a different value for 1000
in the code above.
If you want to wait after sending a request, add this to the end of your test script in Postman.
You can also make this values configurable from outside by using pm.environment.get()
to fetch the delay value via a variable set in your Environment.
For each request, if you want to wait before sending a request, add this to the pre-request script.
setTimeout(function () { console.log("executed delay for 1000 ms"); }, 1000); // delay in 1000 ms
Set your delay to desired value in ms by setting a different value for
1000
in the code above.If you want to wait after sending a request, add this to the end of your test script in Postman.
You can also make this values configurable from outside by using
pm.environment.get()
to fetch the delay value via a variable set in your Environment.
Great! I'll give this a try Thanks
@shamasis should I add the setTimeout inside of the pre-request event callback in newman? or inside the actual Postman pre-request script?
Actual script :-) I made an example. Check this out for inspiration https://www.postman.com/shamasis-net/workspace/shamasis-public-workspace/collection/22968577-9cdc7c6f-5866-4687-ae51-222454f32f1d?ctx=documentation
@shamasis Ah, I get it now. I was thinking that the setTimeout would be in one of the newman event callbacks, which doesn't work.
thanks!