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

    1、断言:让程序判断预期结果和实际结果是否一致。

    (1)特点

    • Postman的断言是使用JavaScript语言编写的,写在Tests标签页里
    • Tests中的脚本在发送请求之后执行,会把断言的结果(PASS/FAIL)最终在Test Results标签页中展示

    (2)常用断言

    • Status code:Code is 200      //判断响应状态码是否等于200
    pm.test("Status code is 200", function () {
        pm.response.to.have.status(200);
    });
    • Response body:Contains string    //判断响应体中是否包含指定的字符串
    pm.test("Body matches string", function () {
        pm.expect(pm.response.text()).to.include("string_you_want_to_search");
    });
    • Response body:Is equal to a string    //判断响应体是否完成等于某个字符串
    pm.test("Body is correct", function () {
        pm.response.to.have.body("response_body_string");
    });
    • Response body:JSON value check    //校验响应的json数据
    pm.test("Your test name", function () {
        var jsonData = pm.response.json();
        pm.expect(jsonData.value).to.eql(100);
    });
    • Response headers:Content-Type header check  //断言响应头信息
    pm.test("Content-Type is present", function () {
        pm.response.to.have.header("Content-Type");
    });

     

  • 相关阅读:
    正则表达式30分钟入门教程
    21 个HTML网页转RSS Feeds的工具
    批量去除PHP文件中bom的PHP代码
    WEB网页采集技术参考
    xcache
    Sonix SN9P701 OCR点读笔二维码识别源码
    UI设计素材资源网站推荐
    解决电信DNS劫持
    自学电子技术的最佳方法
    wp资源汇总
  • 原文地址:https://www.cnblogs.com/wangzicong/p/15654964.html
Copyright © 2011-2022 走看看