简体   繁体   中英

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 ""

================================================================================
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 "\"\"" .

My guess is that in the server code you write, you return ed "" , an empty string. And the HTTP framework json-encoded that and sent two double quotes in the response.

You can turn on logging for Gatling to see more clearly.

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.

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") .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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