Search code examples
scalagatlingscala-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 ""

================================================================================
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??


Solution

  • 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 returned "", 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.