0
votes

Is there a way to 'lock' random value in postman? I would like to generate one random value and use same value for every test in same collection.

this code generate different random value for every test:

pm.environment.set("random", _.random(0,9999999));
2

2 Answers

1
votes

You could you use this in the pre-request:

let randomNum = pm.variables.replaceIn("{{$randomInt}}")

pm.variables.set("randomNum", randomNum) 

Then use {{randomNum}} in the requests.

0
votes

Solution to my problem was setting global variable in 'pre-request script' only for first request of the collection, and leaving 'pre-request script' empty for every next request:

pm.globals.set("randomNum", _.random(0,9999999));

But thanks for your comment anyway @Danny Dainton. I should use 'request' instead of 'test' in my question. What probably misleaded your thinking.