I'm new to Gatling. I could not find a simple complete example of how to see the full HTTP response body.
This is my simple example
class CreateNotecard extends Simulation {
val baseURL = "https://portal.apps.stg.bluescape.com"
val httpConf = http
.baseURL(baseURL)
.userAgentHeader("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1985.125 Safari/537.36")
val scn = scenario("Create a notecard")
.exec(http("Get authenticity token")
.get("/users/sign_in")
.check(bodyString.saveAs("BODY")))
setUp(
scn.inject(atOnceUsers(1))
).protocols(httpConf)
}
How can I print the bodyString into a file or on the console?
Thanks in advance
check(bodyString. saveAs("BODY"))) . exec(session => { val response = session("BODY"). as[String] println(s"Response body: \n$response") session }) // . . . }
To get the response body, you should use the check function and use bodyString. saveAs( “VARIABLE_NAME” ) convention to store the response body.
val printSesssionVar = scenario("print session var"). exec{ session => println(session("<your session var>"). as[String]) session } . From the documentation, it is proper to use something like ${sessionVariable.
Another way to debug Gatling scripts is to print out all the session variables of each virtual user. You can also print out session information for each virtual user that is running. Now all the session info of the virtual user is printed when the HTTP call executes.
Using your example, just add the exec
call below.
class CreateNotecard extends Simulation {
// . . .
.check(bodyString.saveAs("BODY")))
.exec(session => {
val response = session("BODY").as[String]
println(s"Response body: \n$response")
session
})
// . . .
}
Printing directly from the simulation code is useful while debugging it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With