zoukankan      html  css  js  c++  java
  • postman常用断言的一些内置方法

    测试响应码状态是否为200:
    pm.test("Status test", function () { pm.response.to.have.status(200); });
    还可以使用pm.expect语法进行拓展
    pm.test("Status test", function () {
    pm.expect(pm.response.code).to.equal(200);
    });

    验证response time是否小于某个值:
    tests["response time less than 200ms"] = pm.reponseTime < 200;

    pm.test["reponse time less than 200ms",function(){
      pm.expect(pm.response.responseTime).to.below(200);
    }];

    检查响应主体中是否包含某字符串:
    pm.test("检查是否包含某字符串",function(){
      pm.expect(pm.response.text()).to.include("你想检查的内容");
    });

    tests["检查name中是否包含某个值"] = pm.response.name.has("******")

    postman提取返回值中的json字符串作为其它请求的参数:
    var res(自定义名称) = JSON.parse(responseBody)//获取body中返回的所有参数
    tests["名称"] = res.(具体参数如:id) === 值;

    当date里面包含多个json格式数据时,想判断date下第一个json,如何断言:
    var res = JSON.parse(responseBody)

    pm.test(["判断第一个json"],function(){
      pm.expect(res.date[0].id).to.eql(1);
    });

    设置环境变量:
    pm.environment.set("variable_key","varable_value");
    获取环境变量:
    pm.environment.ge("variable_key");

    设置全局变量:
    pm.globals.set("variable_key","variable_value");
    获取全局变量:
    pm.globals.get("variable_key");

  • 相关阅读:
    Android 获取自带浏览器上网记录
    android 中的 ViewPager+ Fragment
    Git分支操作
    图形验证码的识别
    mac平台搭建安卓开发环境
    [报错集合]Uncaught ReferenceError: xxx is not defined
    Centos安装Python3
    VSCode 代码格式化 快捷键
    Mac下用Parallels Desktop安装Ubuntu
    请求头headers
  • 原文地址:https://www.cnblogs.com/-yanrong/p/12677784.html
Copyright © 2011-2022 走看看