断言: tests[要输出的内容]=true会在response的Test Results中产生输出 pm.test(要输出的内容,函数) Pm.test("Status code is 200", function ()[断言内容]); pm.test() pm.test("Status code is 200", function () { pm.response.to.have.status(200); }); 在response中取json数据的值 {"data":"登陆成功","message":"操作成功","status":1} pm.response.json().键名 pm.response.json().message 取response中html/x,l文本数据的值: 正则表达式提取数据值: pm.response.text().match(new RegExp(‘cn/”>(.+?)</string>’)) 字符串.match( new RegExp(正则表达式)) 正则表达式:左边界 想要取得值 有边界 cn/”>(.+?)</string> 变量: 局部变量 js局部变量:只能在脚本区使用 postman局部变量:可以在脚本区使用,也可以在参数区params或body 参数区使用自定义的局部变量:{{变量名}} 前置脚本:Pre-request Script pm.variables.set('变量名','数据值')//定义postman局部变量 pm.variables.set('username','liuyulin')//定义postman局部变量 后置脚本:Tests tests[pm.variables.get('变量名')]=true//获取postman局部变量 tests[pm.variables.get('username')]=true//获取postman局部变量 后置脚本: var user=pm.variables.get('username')//定义js变量保存postman变量 tests[user]=true Postman接口用例各区域执行的顺序: 执行前置脚本区->执行接口请求->获得接口响应->执行后置脚本区 数据(外部)变量 用例集变量 环境变量 全局变量 参数化: 前置/后置脚本区: 多借口联调(关联): 函数、方法的应用
|