zoukankan      html  css  js  c++  java
  • Postman接口测试_添加断言

    1、设置环境变量

    postman.setEnvironmentVariable("variable_key", "variable_value");

    postman.clearEnvironmentVariable("variable_key"); ——清除环境变量

    2、设置全局变量

    postman.setGlobalVariable("variable_key", "variable_value");

    postman.clearGlobalVariable("variable_key"); ——清除全局变量

    3、检查response的body中是否包含字符串

    tests["Body matches string"] = responseBody.has("string_you_want_to_search");

    4、将XML的响应体转换成JSON对象

    var jsonObject = xml2Json(responseBody);

    5、检查response的body是否等于一个字符串

    tests["Body is correct"] = responseBody === "response_body_string";

    6、检查json值

    var jsonData = JSON.parse(responseBody);
    tests["Your test name"] = jsonData.value === 100;

    7、检查响应头内容类型是否存在

    tests["Content-Type is present"] = postman.getResponseHeader("Content-Type");

    8、检查响应时间是否小于200秒

    tests["Response time is less than 200ms"] = responseTime < 200;

    9、检查响应状态码是否为200

    tests["Status code is 200"] = responseCode.code === 200;

    10、检查响应状态码名字是否包含一个字符串

    tests["Status code name has string"] = responseCode.name.has("Created");

    11、通过设置响应状态码来检查post请求是否成功

    tests["Successful POST request"] = responseCode.code === 200 || responseCode.code === 201;

    12、Use TinyValidator for JSON data

    tests["Successful POST request"] = responseCode.code === 200 || responseCode.code === 202;

    var schema = {
    "items": {
    "type": "boolean"
    }
    };
    var data1 = [true, false];
    var data2 = [true, 123];

    tests["Valid Data1"] = tv4.validate(data1, schema);
    tests["Valid Data2"] = tv4.validate(data2, schema);
    console.log("Validation failed: ", tv4.error);

  • 相关阅读:
    AS400一些有用的命令
    Publish的时候某些需要用到的文件没deploy上去
    DB2一些SQL的用法
    根据PostgreSQL 系统表查出字段描述
    linux memcached 安装
    CentOS下XEN虚拟服务器安装配置
    Apache the requested operation has failed
    PHP配置兼容ZendDebugger和Optimizer
    虚拟机比较
    memcache 运行情况,内存使用
  • 原文地址:https://www.cnblogs.com/liruxian/p/10001539.html
Copyright © 2011-2022 走看看