0
votes

I want to use Postman to test the REST API of a project, and I'm trying to a generic request. For example:

I have a POST request that makes a research, the parameters of this research are in the body. How do I automate the request with a pre-request-script that modifies the body at each iteration?

Because I don't want to create a collection with 20 POST requests where only the body changes. I tried to use a while loop in pre-request-script or in test script but Postman executed the request only once. Then I tried to use the runner for calling the request 5 times, for example, and i wrote a script that modified a variable each time, but I think that global and environment variable are reset at each iteration of the runner.

Do you have any ideas?

2
Could you show the scripts as well that you tried executing? - Ray

2 Answers

0
votes

enter image description here

I tried that to modify value of password when I use the runner. But if the runner reset variables at each iteration it can't work.

It's ok I found an other solution: For example I want to test the request with 5 different password, i create 5 file json who correspond to my global variables or environment variables and in this files I modify just one variable. I use newman i a loop script to call the same request with different global variable file to modify just one parameter of the request.

0
votes

You can also use set_nextRequest() (see http://blog.getpostman.com/2016/03/23/conditional-workflows-in-postman/). With this you should be able to force calling your request again with the new value for your password and not perform multiple iterations. If you use a global variable in your json body and you update it in your loop, it should work.

hope this helps

Alexandre