1

I know that we can set a variable in different scopes via a pre-request script, but can we set one for on "execution" or "run of test".

I have a folder that contains two requests to validate a scenario where the first one will create a resource with an unique id and the second one will fail by trying to create a resource with the same unique id.

I would like to generate that unique value each time the collection is run. At this time I use a collectionVariables to test and set when not present but that variable is kept between each "retry".

Can I create a variable that will be the same only for one execution of a collection ?

Thanks

gervais.b
  • 2,294
  • 2
  • 22
  • 46

2 Answers2

1

I have similar cases, where I store the values in Environment variables and then unset them in the Pre-request script of the first request:

pm.environment.unset("myVariable");
Christian Baumann
  • 3,188
  • 3
  • 20
  • 37
0

So, my solution is the same as the one suggested by @so cal cheesehead.

I create a variable in either the folder pre-request or the first request script. And unset it after the last test in the last request.

The sad part is that the initialization and destruction of this variable is spread in different scripts.

gervais.b
  • 2,294
  • 2
  • 22
  • 46