Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gatling: How to display full HTTP response body in the console or print it into a file

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

like image 978
Vladimir Avatar asked Oct 27 '17 00:10

Vladimir


People also ask

How do you print a response body in Gatling?

check(bodyString. saveAs("BODY"))) . exec(session => { val response = session("BODY"). as[String] println(s"Response body: \n$response") session }) // . . . }

How do you check your body response in Gatling?

To get the response body, you should use the check function and use bodyString. saveAs( “VARIABLE_NAME” ) convention to store the response body.

How do I print a session variable in Gatling?

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.

How do you debug a Gatling script?

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.


1 Answers

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.

like image 99
Paulo Merson Avatar answered Sep 27 '22 21:09

Paulo Merson