In this tutorial I want to share my method to iterate a request in postman collection, so it will run several times.
To simulate API response body I create an API mock using mocky. To see my mock API you can click here.
Without a further ado I will demonstrate how to loop a postman request.
- In collection level click Triple dot >> Edit >> Variables
![](https://cdn-images-1.medium.com/max/800/1*2zfIFGkOH9AhUEQXsopvUQ.png)
2. In tab Variables tab, type in type in count with current value 5, then click Update. This step will create new variable in collection level.
![](https://cdn-images-1.medium.com/max/800/1*0i5Qt22SgW17Afd86lHHJA.png)
3. Create new request. For this simulation I will use request from this story. But I will modify the test script. In the test script add script as follows.
var currentCount = pm.collectionVariables.get("count")
if (currentCount > 0){
currentCount = currentCount -1 ;
pm.collectionVariables.set("count", currentCount);
postman.setNextRequest("Get books detail (loop)");
}
4. Save request and run collection. To make it works, one can’t run the test by clicking “Send” button. We must run it using collection runner.
![](https://cdn-images-1.medium.com/max/800/1*0Kg0f8rttmSl5DqwYZK5GA.png)
5. Run it and Voila!! we’ll get another 5 request running.
![](https://cdn-images-1.medium.com/max/800/1*5vZ3XfxM_8W5liOzz63ldw.png)
Thank you for reading my story. Hope it will helps you.
Follow me on
Facebook: https://www.facebook.com/mydoqa/
Instagram: https://www.instagram.com/mydoqa/
Twitter: https://twitter.com/MydoQa
0 comments:
Post a Comment