Hi I am new in postman and I need a little help. I need to run the same request with same parameters 4 times, 3 of them should be with success and in 4th time I should receive a backend message and the final result is to check this message. But it is a bit complicated because every time before sending this request I should send another one. Is it possible?
1 Like
Hi @ghazaryan.nelli!
Yes, you can accomplish this by looping using postman.setNextRequest('request_name');
.
https://learning.postman.com/docs/postman/scripts/branching-and-looping/
You’ll need to make the loop conditional on the number of times you’ve looped already. I’d recommend doing something like this in a test script:
if(!pm.variables.has('counter')) {
pm.variables.set('counter',0);
}
var counter = pm.variables.get('counter');
counter++;
pm.variables.set('counter', counter);
if (counter < 5) {
postman.setNextRequest('your_request_name');
} else {
postman.setNextRequest(null);
}
1 Like
Hey John-paul. Thank you so much. I’ll set this up.