Can I somehow change env token depending on the number of tests running?

Let’s say I’m gonna run 20 tests in a row, I’ve got defined 3 env variables:

  • token
  • evenToken
  • oddToken

What I’d like to do with it, is to change which token should be used within test, let’s say all of them will initially use var ‘token’, but depending on this test’s number (even/odd) I’d like to replace it with one of the others.

  • So my first question is about determining within test itself, what is it’s number in queue?
  • Then, when I know how to check the number of running test, I’ll be able to set token with the code below (according to the research - I didn’t test it yet), so I’d like to know how to combine these together.

pm.environment.set(“token”, pm.variables.get(“evenToken”));
pm.environment.set(“token”, pm.variables.get(“oddToken”));

  • Maybe I should do that in 'pre-request Script' instead of 'tests' section?
  • Got my anwser for that one already from test docs (pre-request Script);

Also feel free to suggest any other workaround, I need a solution to run every next test with the other token (it’s a bidding endpoint and when you are identified by the same token in short you will get rejected because of trying to overbid youself). But that also brings another subject, can I modify request’s value for every next test in queue? in this case every test should have ‘amount’ higher than the previous one, let’s say by adding +1.

Every help appreciated.

It looks like in theory, it can be dealt with by variables, by looking at the docs it should be possible to set iterator var and in pre-request script just increment it, then check this value and reassign token if needed, seems like a solution for me.

I’ll give a feedback after implementation.

EDIT:

Works like a charm.