zoukankan      html  css  js  c++  java
  • postman断言作用及怎么使用

    这段时间一直在学习postman,在请求中使用断言,很多人不是很了解postman断言,其实呢,postman断言是JavaScript语言编写的,在postman客户端指定区域编写即可。

    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["Your test name"] = data.value === 100;

    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 POST request status code

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

  • 相关阅读:
    微信开发 之 开启开发模式
    微信公众号开发 之 编辑模式使用
    分析各种Android设备屏幕分辨率与适配
    【面向对象设计模式】 适配器模式 (二)
    重构 之 总结代码的坏味道 Bad Smell (一) 重复代码 过长函数 过大的类 过长参数列 发散式变化 霰弹式修改
    【Android 应用开发】Android资源文件
    java 创建并写入文件
    隐藏 HttpClient 在console的日志
    HOW TO CHANGE THE DEFAULT KEY-VALUE SEPARATOR OF A MAPREDUCE JOB
    java 时间戳转换
  • 原文地址:https://www.cnblogs.com/yyf-sally/p/6601686.html
Copyright © 2011-2022 走看看