简体   繁体   English

Gatling 场景检查响应正文的确切内容

[英]Gatling scenario check the exact content of the response body

I'm sending a request like below and expect the body of the response to be "" (see check below):我正在发送如下请求,并希望响应的主体为"" (请参阅下面的检查):

  val runGraphScn = scenario("runGraph Scenario")
    .exec(http("POST runGraph")
      .post("/runGraph")
      .body(InputStreamBody(getClass.getResourceAsStream("/rungraph_req_body.json")))
      .check(
        status is 200,
        bodyString is ""
      )
    )

But when I run the scenario I see it failing bodyString.find.is(), found ""但是当我运行这个场景时,我看到它失败bodyString.find.is(), found ""

================================================================================
2020-07-24 17:09:20                                          55s elapsed
---- Requests ------------------------------------------------------------------
> Global                                                   (OK=1      KO=2     )
> POST runGraph                                            (OK=0      KO=1     )
> GET getProject                                           (OK=1      KO=0     )
> POST /runGraphResult                                     (OK=0      KO=1     )
---- Errors --------------------------------------------------------------------
> bodyString.find.is(), found ""                                      1 (50.00%)
> status.find.is(200), but actually found 404                         1 (50.00%)

How can I check that the response body is empty??如何检查响应正文是否为空?

The body of your response is indeed "" .您的回复内容确实是"" Not empty, but literally the two quotation marks.不是空的,而是字面上的两个引号。 The test will pass if your check is bodyString is "\"\"" .如果您的检查是bodyString is "\"\"" ,则测试将通过。

My guess is that in the server code you write, you return ed "" , an empty string.我的猜测是,在您编写的服务器代码中,您return ed "" ,一个空字符串。 And the HTTP framework json-encoded that and sent two double quotes in the response. HTTP 框架对其进行 json 编码并在响应中发送两个双引号。

You can turn on logging for Gatling to see more clearly.您可以打开 Gatling 的日志记录以更清楚地查看。

I can't reproduce (tried with master branch) so I suspect you actually have some non printable char, either in your response body, or in your expected result.我无法重现(尝试使用 master 分支),所以我怀疑您实际上有一些不可打印的字符,无论是在您的响应正文中,还是在您的预期结果中。

Please check your Content-Length and your Simulation.请检查您的内容长度和模拟。

If that's not the issue, please provide a Short, Self Contained, Correct (Compilable), Example .如果这不是问题,请提供一个简短的、自包含的、正确的(可编译的)示例

Side note regarding InputStreamBody(getClass.getResourceAsStream("/rungraph_req_body.json")) : overly complicated, you should just use RawFileBody("rungraph_req_body.json") .关于InputStreamBody(getClass.getResourceAsStream("/rungraph_req_body.json")) :过于复杂,您应该只使用RawFileBody("rungraph_req_body.json")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM