1
votes

Gatling 2.0. I'receiving from server the following json of Events:

[  
   {  "a":"a","b":"b","c":"c","d":"d"},
   {  "a":"a1","b":"b1","c":"c1","d":"d2" },
   { "a":"a2","b":"b2","c":"c2","d":"d3" }
]

Now I would like to store it in session as List of Event classes

case class Event(a:String:b:String,d:String)

I'm trying to do the following

jsonPath("$.chats.chat[0].events.event").ofType[Seq[Any]].transform(_.map{ l =>

                Some(Event(l(0).asInstanceOf[String], l(1).asInstanceOf[String],l(3).asInstanceOf[String])).saveAs("events")

but this line does not compile: Please help.

  1. after it I would like to fetch this list from session, Can i do it by:

    val events = session("events").as[Seq[Events]]

Thanks.

1
Why are you wrapping your Event in an Option ?Pierre DAL-PRA
@PierreDAL-PRA. IIRC, this was the signature in 2.0. It was changed in 2.1.Stephane Landelle
@PierreDAL-PRA My bad, it was changed before releasing 2.0 :)Stephane Landelle

1 Answers

2
votes

You're using transform, which takes the extract result and transform it into something else.

Here, as you don't specify the check ordinality, you use the default, find, that only get you the first result of the extraction step. I doubt $.chats.chat[0].events.event is what you want, it would probably return a Map (a javascript Object). You probably want $.chats.chat[0].events.

Then regarding, storing and accessing data into the Session, you shouldn't try storing them in classes if you're not used to Scala.

Instead, upgrade to Gatling 2.1 that has improved EL capabilities, so you can write things like ${event.foo.bar} (which you can't with Gatling 2.0).