【问题标题】:How to read the contents of a Post request on Postman?如何在 Postman 上读取 Post 请求的内容?
【发布时间】:2020-09-27 13:14:15
【问题描述】:

在我正在测试的系统中,存在响应通知 200(ok)的情况,但内容可能表明后端服务的内部验证出现错误。如果此服务错误代码按预期出现,我如何使用 Postman 读取响应内容并安排成功验证?

【问题讨论】:

    标签: testing automation postman web-api-testing


    【解决方案1】:

    您可以使用 Postman 中的测试选项卡对正文(JSON 和 XML)运行检查。有 sn-ps 向您展示语法。您可以调整它们以检查响应正文中指示错误的元素。

    【讨论】:

      【解决方案2】:

      Postman 有一个名为“测试”的选项卡,您可以在其中提供测试脚本以供执行。 如果您想验证您的请求以 200 OK 响应,以下是脚本

      pm.test("Status test", function () {
      pm.response.to.have.status(200);
      });
      

      如果要验证响应是否包含任何指定的字符串,

      pm.test("Body matches string", function () {
      pm.expect(pm.response.text()).to.include("string_you_want_to_search");
      });
      

      在您的情况下,我假设可以使用上述脚本。如果响应正文是 JSON,

      pm.test("JSON Body match", function () {
      var respBody = pm.response.json();
      pm.expect(respBody.<json node>).is.to.equal("Error_name");
      });
      

      示例 JSON 响应正文 { “身份证”:100, “状态”:“错误请求” }

      pm.test("JSON Body matches string", function () {
      var respBody = pm.response.json();
      pm.expect(respBody.status).is.to.equal("Bad Request");
      });
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2021-12-25
        • 2019-10-11
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-08-22
        • 1970-01-01
        相关资源
        最近更新 更多