• 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);

  • 相关阅读:
    HDU1875——畅通工程再续(最小生成树:Kruskal算法)
    CodeForces114E——Double Happiness(素数二次筛选)
    POJ3083——Children of the Candy Corn(DFS+BFS)
    POJ3687——Labeling Balls(反向建图+拓扑排序)
    SDUT2157——Greatest Number(STL二分查找)
    UVA548——Tree(中后序建树+DFS)
    HDU1312——Red and Black(DFS)
    生活碎碎念
    SQL基础四(例子)
    Linux系统中的一些重要的目录
  • 原文地址:https://www.cnblogs.com/carey9420/p/13437902.html
Copyright © 2020-2023  润新知