场景:
在发送请求前需要随机生产一些参数值
方式:
通过postman中的Pre-request Script集合postman.setEnvironmentVariable使用
例如在发送请求前需要一个str格式的参数,可以在Pre-request Script中先使用Script随机出来一个str
("0000" + (Math.random()*Math.pow(36,4) << 0).toString(36)).slice(-4)
在通过postman.setEnvironmentVariable 设置为环境变量
postman.setEnvironmentVariable("random_username", ("0000" + (Math.random()*Math.pow(36,4) << 0).toString(36)).slice(-4));
在body中通过{{}}获取变量使用