postman提取返回值和断言

将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;

猜你喜欢

转载自www.cnblogs.com/hanjiajiejie/p/9037526.html
今日推荐