Functions

Use functions to programmatically generate dynamic parameters

Sometimes, you might want to dynamic parameters that are too complex to compute for Gatling EL. Most Gatling DSL methods can also be passed a function to compute your parameter value programmatically.

Syntax

Those functions always take a Session parameter, so you can extract previously stored data.

The generic signature of these functions is:

  • In Java and Kotlin: Session -> T
  • In Scala: Expression[T] is an alias for Session => Validation[T]. Values can implicitly lifted in Validation.
     
// inline usage with a Java lamdba
exec(http("name")
  .get(session -> "/foo/" + session.getString("param").toLowerCase(Locale.getDefault())));

// passing a reference to a function
Function<Session, String> f =
    session -> "/foo/" + session.getString("param").toLowerCase(Locale.getDefault());
exec(http("name").get(f));
// inline usage with a Java lamdba
exec(http("name")
  .get { session -> "/foo/${session.getString("param").toLowerCase(Locale.getDefault())}" })

// passing a reference to a function
val f =
  { session: Session -> "/foo/${session.getString("param").toLowerCase(Locale.getDefault())}" }
exec(http("name").get(f))
// inline usage with an anonymous function
exec(http("name")
  .get(session => s"/foo/${session("param").as[String].toLowerCase(Locale.getDefault)}"))

// passing a reference to a function
val f: Expression[String] =
  session => s"/foo/${session("param").as[String].toLowerCase(Locale.getDefault)}"
exec(http("name").get(f));

Edit this page on GitHub