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;

 

posted @ 2018-05-14 18:25  韩家姐姐  阅读(2496)  评论(0编辑  收藏  举报