Collection Runner prevents environment variables from being updated

Hello,

There’s this collection I’ve been using for a while that stores part of the response of a request using pm.environment.set(key, value).

Earlier I tried adding another part of the response into another environment variable, and realised the entire collection was unable to update the environment.
EDIT: This is when the collection is run from the collection runner. IF the requests are sent one by one it is fine.

The weird thing is that the first collection continued to run at all despite needing up-to-date environment values for the requests to clear. So it’s like it was using another phantom environment, which I don’t know how to do.

Is there a parameter somewhere that I might have missed? Or is it related to the update ?
Thanks for any hints, I might have to recreate a few collections otherwise.

1 Like

Can you provide some visual examples of the issue, so that we can see where the problem might be?

Another thing to ensure is that you’re collection and the requests are saved (no orange dots in the tabs) before running the Collection again. The Runner will not know about those changes unless you save them, it will continue to run the old values.

Oh yes i have done the mistake of not having saved a request properly before, so I made sure this was not the case here before posting.
Alright for visuals, here is the last request from my collection


This EventListenerId is the result of a previous request, and must be up-to-date to function properly, which is what I mentioned previously.
the last two pm.environment.set are there for this test.
If I run this collection, no error from lack of eventListenerId, but none of the environment variables change .
I realised that if I send the requests one by one (without the runner), the environment is updated properly. This is highly impractical though.

Tried the runner on another computer with an older version, then in another workspace and the result was the same.

(edit: messed up a bit with a previous edit and duplicated the post accidently, so i deleted one)

1 Like

I am using a setInterval method to send each 5 mins a request and I want to for every sent request sum 1 to a collection variables call quantityResquest

@solidsnekdrive , is it possible the folder you ran did not run to completion?

I was having this problem as well while trying to debug some bad requests in my folder. Because the folder is large and the errors happened with the earliest requests, I became impatient and clicked the red “Stop Run” button. I would tweak the bad requests and then try to run them individually which is when I noticed my environment variables were not updating as I expected. Then I noticed this tooltip for the “Keep variable values” option in the folder runner options:

Notice how it says “at the end of the run”? When I tried a different folder that did not have errors, it completed as expected and also updated the environment variables as expected.

It appears that the runner keeps track of variables during the run and only updates your environment variables when the run is completed.

I am having a similar issue as well.

I am using Postman Runner for running performance test. It is however unable to modify collection variables via code set in the Pre-request Script tab of one of the requests in my collection.

I have set below code in the Pre-request Script tab of a POST request -

let accountId = pm.collectionVariables.get("accountId");
++accountId // increment by 1
pm.collectionVariables.set("accountId", accountId);
console.log("Current value of accountId: " + pm.collectionVariables.get("accountId"));

The collection variable “accountId” seen above gets incremented and read fine via another GET request as well, when I run these Requests outside of the Runner. But when running the collection as part of the performance test, for some reason the pre-script code does NOT seem to be getting executed. At least that’s what the execution results indicate since the accountId remains unchanged.

Has anyone been able to resolve or find a workaround for this issue? Or am I missing something?

Thank you.

It’s been a while so I forgot why I was doing this, but this was the conclusion I came to regarding this topic (same as @chasebarrett-ideiio pretty much):
Environment variables are not updated as the collection is being run, but only once it completes.
This also means that if you interrupt the runner, it never “completes” and the values are not updated. This was very surprising because the values have to be stored somewhere for the runner since some requests depend on updated values and work fine during the run. They just get scrapped if you cancel.

yes after struggling with concept, i landed on my intended page and found that
every variable be it a collection global or environmental variable will be updated to the intended tab only after the full collection run and if it’s interrupted in between then nothing will be saved.

even I try to verify that if variables are somehow stored in interrupted flow if I uncheck this box but no success, Actually if the checkbox is unchecked, then no variable value is stored even in case of complete runner flow.