Oskiii
Oskiii

Reputation: 19

Can't use Gatling Expression Language inside my own code/functions

I'm creating one report for all simulations in SCALA, in part of them I don't have all attributes and I need to replace that because I'm getting no attribute defined error.

I was trying below code and many many more:

val dbc_communityID = if ("${communityID.exists()}" == true) "${communityID}" else "N/A"

I always have "N/A". I also checked

== 1

== "true"

I spend definitely to much time of that, Please help

Upvotes: 0

Views: 1551

Answers (2)

Stéphane LANDELLE
Stéphane LANDELLE

Reputation: 6608

Quoting Gatling official documentation:

This Expression Language only works on String values being passed to Gatling DSL methods. Such Strings are parsed only once, when the Gatling simulation is being instantiated.

For example queryParam("latitude", session => "${latitude}") wouldn’t work because the parameter is not a String, but a function that returns a String.

Also, queryParam("latitude", "${latitude}".toInt) wouldn’t because the toInt would happen before passing the parameter to the queryParam method.

The solution here would be to pass a function:

session => session("latitude").validate[Int].

In short: you can't mix Gatling EL and functions/custom code. If you want to implement some custom logic that deals with Session data, you have to use the Session API, eg:

session => session("communityID").asOption[String].getOrElse("N/A")

Upvotes: 3

Tim
Tim

Reputation: 27356

if ("${communityID.exists()}" == true)

You are comparing a fixed String with a Boolean so the result will always be false. There is probably a compiler warning about this.

It is possible that you want this, but hard to say without know more about the rest of the code:

if (s"${communityID.exists()}" == "true")

But in that case it is simpler to write

if (communityID.exists())

Upvotes: -2

Related Questions