Disclaimer:
the approach I am following may not be the best one but this is the one with which I was thinking to reach my goal, if there’s a better solution feel free to suggest it please.
Problem:
In a custom script where I am using Newman as package I am running a Postman collection by using the iterationCount parameters (see this) so to loop the same collection in many iterations. In each iteration I am saving a dynamic data I am interested with as an environment variable: var body = JSON.parse(responseBody); postman.setEnvironmentVariable("cart_uuid", body.uuid);
Obviously this means that the environment variable is overwritten at each iteration.
The problem is as far as I understood in Newman the environment variables are only accessible in the done callback see this that’s to say “when a collection run has completed, with or without errors”. In other words it means that I can not intercept it during the iterations in my script (while I wanted to do it on the iteration callback).
Could you tell me how can I resolve this problem of getting pragrammatically the environment variables in Newman used as package in an iteration?
Could you give us an idea about the requests inside that folder you’re running. If you were to run what you’re doing manually inside the app, what’s happening.
I can see that you’re setting a new variable somewhere but not really sure how that relates to the rest of the requests.
Is the request going to the same URL each time but the response is returning a different unique guid?
please check the collection you will see it directly in any case what you said is correct: Is the request going to the same URL each time but the response is returning a different unique guid?
Yes only some parameters are changing in the request.
In any case here is what I am interesting to fetch in my script which uses Newman after each iteration
I mocked out a very simplified version of what you’re running (might not be 100% correct) but it seems to be creating a new guid and sending that in the second POST request each iteration.
What I needed to understand is how can I resolve this problem of getting programmatically the environment variables in Newman used as package in an iteration on a script which uses Newman run and the callbacks.