postman学习之常用断言

 1. 检查响应体中是否包含指定字符串
   pm.test("Body matches string",function(){
    pm.expect(pm.response.text()).to.include("新闻");
   });
   //tests方法
   tests["Body matches string"] = responseBody.has("新闻");
   
 2. 检查响应状态码
   //判断响应码是否为200
   pm.test("Status code is 200",function(){
    pm.response.to.have.status(200);
   });
   //判断响应码是否为某个值
   pm.test("Response successful",function(){
    pm.expect(pm.response.code).to.be.oneOf([200,201,202]);
   });
   //直接判断响应状态是否正常
   //常见有ok(200),notFound(404),error(4XX,5XX),success(2XX)
   pm.test("Response status is OK",function(){
    pm.response.to.be.ok;
   });
   //另一种方法:tests判断响应码
   tests["status code is 200"]=responseCode.code === 200;
   
 3. 检查响应时间
   //判断响应时间小于200ms
   pm.test("ResponseTime is lesson than 200",function(){
    pm.expect(pm.response.responseTime).to.be.below(200);
   });
   //tests方法判断
   tests["ResponseTime is less than 300ms"]=responseTime < 200;
   
 4. 检查响应头中是否包含某一参数
   //以Content-Type内容类型为例
   tests["Content-Type is present"]=postman.getResponseHeader("Content-Type");
   tests["Content-type is present"]=responseHeaders.hasOwnProperty("Content-Type");

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值