可以在 URL,参数,标头,授权,正文和标头预设中使用变量
一、Test脚本中自定义变量(Test是处理接口返回结果,提取结果和断言等)
// 设置为环境变量
pm.environment.set("token", jsonData.token);
// 设置为全局变量
pm.globals.set("variable_key", "variable_value");
// 设置为集合变量
pm.collectionVariables.set("variable_key", "variable_value");
// 设置为局部变量
pm.variables.set("variable_key", "variable_value");
// 设置为删除变量
pm.environment.unset("variable_key");
二、随机变量
https://learning.postman.com/docs/writing-scripts/script-references/variables-list/
$guid:v4样式的guid(全局唯一标识符)
$timestamp:当前Unix时间戳
$randomInt:0到1000之间的随机整数
$isoTimestamp:当前系统使时间
$randomUUID:随机生成UUID(通用唯一识别码)