使用场景举例:使用postman测试,调用获取token的接口获取token,后续的接口均需要token作为参数
在postman调用获取token的接口时
pm.test("Status code is 200", function () {
pm.response.to.have.status(200);
});
// 把responseBody转为json字符串
var data = JSON.parse(responseBody);
postman.setEnvironmentVariable('token', 'bearer ' + data.access_token)
这样在运行完接口后会将token保存在环境变量中 ,格式为:bearer ********,使用的方法则是{{token}},具体如下