Hi, I am trying to create my gRPC payload by reading data from a csv file(it has guestID and category as columns) but I see ${guestID} is being passed to my service instead of the actual value in csv file. I think EL is unable to interpret it at runtime. I also have “import io.gatling.core.Predef.stringToExpression” in my script. How can I achieve this? Am I doing something wrong here? Any help is appreciated. (payload is a RequestContext object which takes in metadata, keys and items. metadata is a map, keys is a Seq of ContextKey and items is empty Seq. ContextKey contains string guestID or category and type).
Please carefully read the documentation: Gatling Expression Language is not some that can magically work in your own custom code, only when passed to Gatling DSL methods.
To use it you always need the current user session instance:
`
// simple var
val id = ELParser("${call_id}", session)
// nested object
val organizationId = ELParser("${organization_data.id}", session).asInstanceOf[String]
// any EL function works
val exists = ELParser("${call_data.recording_data.transcript.exists()}", session).asInstanceOf[Boolean]
// or return option to prevent exception if key not found
val language = ELParser.asOption("${call_data.recording_data.language}", session).asInstanceOf[Option[String]]
I’m not convinced using the EL parser explicitly to manually turn Gatling EL Strings into functions is a good thing.
I recommend using the programmatic Session API instead.
// simple var
val id: Expression[String] = session => session(“call_id”).as[String]
I don’t think that’s the case.
Using for comprehension, it can be achieved with one line per session attribute access without callback hell indentation.
For an example, see my answer for this question on stackoverflow.
I see what you mean now. I thought you were talking about the nested flatMap (what for comprehension desugars to) for multiple session attribute accesses.
I guess trying to write that nested access succinctly manually will result in bad Scala code, as the EL compiler has to do quite a few dynamic type checking behind the scenes.