将token接口中返回的access_token设置为全局变量。
如:token接口返回格式为:
{
"data": {
"access_token": "xxx",
"expires_in": xxx
},
"err": 0,
"msg": "success"
}
js脚本为:
var jsonData = JSON.parse(responseBody);
postman.setEnvironmentVariable("Auth",jsonData.data.access_token);
test断言:
tests["msg"] = jsonData.msg === "success";
tests["Status code is 200"] = responseCode.code === 200;