Home > database >  Print gatling session map values on console
Print gatling session map values on console

Time:11-03

I am fairly new to gatling, and I am trying to print out Map values of session to the console. The values saved in the session are of the format.

sessionVariable -> Map (key1 -> Map(nkey1 -> nval1, nkey2 -> nval2 ...), key2 -> val2, key3 -> val3)

I am trying to get the val2 or even nval1 from the session variable.

From this question and this question, I see I could do something like

val printSesssionVar = scenario("print session var").exec{
    session =>
      println(session("<your session var>").as[String])
      session
  }
.

So I have tried

 val printSesssionVar = scenario("print session var").exec{
    session =>
      println(session("sessionVariable(2)").as[String])
      println(session("sessionVariable[2]").as[String])
      println(session("${sessionVariable[2]}").as[String])
      println(session("${sessionVariable.key2}").as[String])
      session
  }

From the documentation, it is proper to use something like ${sessionVariable.key2} in a method, but I want to print the results to console.

but none seem to work. Please any suggestions?

CodePudding user response:

Actually, I found a way; that is, getting the variable from the session not as a string but as a Map which is the right format of the data returned.

val printSesssionVar = scenario("print session var").exec{
    session =>
      val varFromSession = session("sessionVariable(0)").as[Map[String, Any]])
      println(varFromSession("key2"))
      session
  }
  • Related