zoukankan      html  css  js  c++  java
  • 【Postman学习】Postman断言

    Postamn断言

     1 断言内容详解
     2 postman断言是JavaScript语言编写的,在postman客户端指定区域编写即可。
     6 1.设置环境变量--Setting an environment variable 
     7 postman.setEnvironmentVariable("key", "value");
     8 
     9 2.设置全局变量--Set a global variable
    10 postman.setGlobalVariable("key", "value");
    11 
    12 3.检查响应中包含string--Check if response body contains a string
    13 tests["Body matches string"] = responseBody.has("string_you_want_to_search");
    14 
    15 4.转化XML格式的响应成JSON对象---Convert XML body to a JSON object
    16 var jsonObject = xml2Json(responseBody);
    17 
    18 5.检查响应body中等于指定string--Check if response body is equal to a string
    19  tests["Body is correct"] = responseBody === "response_body_string";
    20 
    21 6.检查JSON某字段值--Check for a JSON value
    22 var data = JSON.parse(responseBody);
    23 
    24 tests["Your test name"] = data.value === 100;
    25 
    26 7.检查Content-Type是否包含在header返回(大小写不敏感)--Content-Type is present (Case-insensitive checking)
    27  tests["Content-Type is present"] = postman.getResponseHeader("Content-Type"); //Note: the getResponseHeader() method returns the header value, if it exists.
    28 
    29 8.检查Content-Type是否包含在header返回(大小写敏感)--Content-Type is present (Case-sensitive)
    30  tests["Content-Type is present"] = responseHeaders.hasOwnProperty("Content-Type");
    31 
    32 9.检查请求耗时时间小于200ms--Response time is less than 200ms
    33 tests["Response time is less than 200ms"] = responseTime < 200;
    34 
    35 10.检查Status code为200--Status code is 200
    36 tests["Status code is 200"] = responseCode.code === 200;
    37 
    38 11.检查Code name是否指定string--Code name contains a string
    39  tests["Status code name has string"] = responseCode.name.has("Created");
    40 
    41 12.检查成功post的请求status code--Succesful POST request status code
    42 tests["Successful POST request"] = responseCode.code === 201 || responseCode.code === 202;
    作者:gtea 博客地址:https://www.cnblogs.com/gtea
  • 相关阅读:
    VMware 11安装Mac OS X 10.10 (转载)
    ios]企业开发者账号申请
    SQL SERVER sa无法登陆的问题
    接触Ubuntu的第一周大致总结
    疯狂VirtualBox实战讲学录 以及 virtualbox完全学习手册 之我见
    必须使用角色管理工具 安装或配置microsoft.net framework 3.5
    02_brk/sbrk
    How to install qt5.9
    026_pickle
    024_iterator
  • 原文地址:https://www.cnblogs.com/gtea/p/12668195.html
Copyright © 2011-2022 走看看