zoukankan      html  css  js  c++  java
  • postman断言

    postman断言是JavaScript语言编写的,在postman客户端的test区域编写即可,
    断言会在请求返回之后,运行,并根据断言的passfail情况体现在最终测试结果中。
    断言如下:
    1.设置环境变量--Setting an environment variable
    postman.setEnvironmentVariable("key", "value");
    2.设置全局变量--Set a global variable
    postman.setGlobalVariable("key", "value");
    3.检查响应中包含string--Check if response body contains a string
    tests["Body matches string"] = responseBody.has("string_you_want_to_search");
    4.转化XML格式的响应成JSON对象---Convert XML body to a JSON object
    var jsonObject = xml2Json(responseBody);
    5.检查响应body中等于指定string--Check if response body is equal to a string
    tests["Body is correct"] = responseBody === "response_body_string";6.检查JSON某字段值--Check for a JSON value
    var data = JSON.parse(responseBody);
    tests["json test"] = data.showDes === "0001";
    针对JSON数据:tests["aaa"] = data.books[0].pubdate === "1972年4月";
    7.检查Content-Type是否包含在header返回(大小写不敏感)--Content-Type is
    present (Case-insensitive checking)
    tests["Content-Type is present"] = postman.getResponseHeader("Content-Type");
    //Note: the getResponseHeader() method returns the header value, if it exists.
    8.检查Content-Type是否包含在header返回(大小写敏感)--Content-Type is
    present (Case-sensitive)
    tests["Content-Type is present"] = responseHeaders.hasOwnProperty("Content-
    Type");
    9.检查请求耗时时间小于200ms--Response time is less than 200ms
    tests["Response time is less than 200ms"] = responseTime < 200;
    10.检查Status code为200--Status code is 200
    tests["Status code is 200"] = responseCode.code === 200;
    11.检查Code name包含指定string--Code name contains a string
    tests["Status code name has string"] = responseCode.name.has("Created");
    12.检查成功post的请求status code--Succesful

  • 相关阅读:
    .Net中的设计模式——Decorator模式
    PetShop的系统架构设计
    PetShop数据访问层之消息处理
    对象的封装与C#的类
    Flash/Flex学习笔记(46):正向运动学
    Flash/Flex学习笔记(43):动量守恒与能量守恒
    win7下恢复“经典任务栏”/“快速启动栏”,关闭“窗口自动最大化”
    Flash/Flex学习笔记(50):3D线条与填充
    图片的javascript延时加载
    Flash/Flex学习笔记(51):3维旋转与透视变换(PerspectiveProjection)
  • 原文地址:https://www.cnblogs.com/strggle/p/6563688.html
Copyright © 2011-2022 走看看