首页 > 解决方案 > Postman, Set on evraibale for "run session"

问题描述

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

标签: postmanpostman-collection-runnerpostman-pre-request-script

解决方案


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");

推荐阅读