请选择 进入手机版 | 继续访问电脑版

湖南新梦想

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 395|回复: 0

postman之断言

[复制链接]

21

主题

21

帖子

112

积分

注册会员

Rank: 2

积分
112
发表于 2022-8-31 21:24:12 | 显示全部楼层 |阅读模式
断言:
tests[要输出的内容]=true会在responseTest 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
responsehtml/x,l文本数据的值:
正则表达式提取数据值:
pm.response.text().match(new RegExp(cn/>.+?</string>))
字符串.match( new RegExp(正则表达式))
正则表达式:左边界 想要取得值 有边界
cn/>.+?</string>
变量:
  局部变量
js局部变量:只能在脚本区使用
postman局部变量:可以在脚本区使用,也可以在参数区paramsbody
参数区使用自定义的局部变量:{{变量名}}
前置脚本: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接口用例各区域执行的顺序:
执行前置脚本区->执行接口请求->获得接口响应->执行后置脚本区
  数据(外部)变量
  用例集变量
环境变量
全局变量
参数化:
   前置/后置脚本区:
   多借口联调(关联):
   函数、方法的应用

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|小黑屋|湖南新梦想 ( 湘ICP备18019834号-2 )

GMT+8, 2023-11-28 23:53 , Processed in 0.040664 second(s), 19 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表