postman获得上一个接口的值

2022-04-28  本文已影响0人  lxzh504

1.var result = json.parse(requestBody);
//把值作为全局变量;
pm.globals.set("assess_token",result.assess_token);

第二个接口:
{{assesss_token}}}

2.使用正则表达式来进行;
new RegExp(' "access_token":"(.*?)" ')

postman的内置参数:
{{timestamp}} 生成当前时间的时间戳 {{randomInt}} 生成0到1000之前的随机数
{{$guid}} 生成guid字符串
自定义的动态参数是在
pre-request script中进行配置的。
//手动获取时间戳
var definedTime = Date.now()
//设置全局变量
pm.globals.set("times",times);
//使用时
{{times}}

postman中的断言:
pm.response.to.have.status(200)

在断言中获得自定义的参数:
pm.globals.get("times")
globals["times"]
globals.times

pm.expect(pm.response.text()).to.include("mashang"+globals["times"])

上一篇 下一篇

猜你喜欢

热点阅读