postman常用断言

一、状态码200

pm.test("Status code is 200", function () {

    pm.response.to.have.status(200);

});

二、响应body包含字符串

pm.test("Body matches string", function () {

    pm.expect(pm.response.text()).to.include("填入校验的字符串");

});

三、响应body等于字符串

pm.test("Body is correct", function () {

    pm.response.to.have.body("输入期望接口返回的结果值");

});

四、响应时间断言

pm.test("Response time is less than 200ms", function () {

    pm.expect(pm.response.responseTime).to.be.below(填入期望的时间,单位ms);

});

五、JSON结果值返回校验

pm.test("Your test name", function () {

    var jsonData = pm.response.json();

    pm.expect(jsonData.字段).to.eql(期望字段值);

});

举例:响应主体{"code":"S","msg":"SUCCESS","data":[{"employeeCode":"100000001","employeeName":"王","time":"09:27:33"}]}

判断code是否为S           pm.expect(jsonData.code).to.eql("S");

判断employeeName是否为王      pm.expect(jsonData.data[0].employeeName).to.eql("王");

六、接口A返回值,用在B接口  

//解析json

var jsonData = pm.response.json();

//取值

var employeeCode=jsonData.data[0].employeeCode;

//调试,再view-show postman console中可查看

console.log(employeeCode);

//设置全局变量

pm.globals.set("gh", employeeCode);

//B接口可直接调用,l例如:http://xxx.xxx.com/getCode?employeeCode={{gh}}

 

 

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值