Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/gatling/gatling.io-doc/llms.txt

Use this file to discover all available pages before exploring further.

Gatling’s Expression Language (EL) is a lightweight templating system that lets you embed dynamic, per-user values into request parameters, URLs, headers, and body strings without writing full Java, Kotlin, or Scala functions. When a Gatling SDK method receives a String argument, it checks whether that string contains #{...} placeholders and, if so, resolves them against the virtual user’s current Session at request time. This means that attributes populated by feeders, previous checks, or exec(session -> ...) blocks are instantly available in any subsequent EL-capable method call.
EL interpolation only happens inside Gatling SDK method arguments. You cannot use "#{foo}" inside your own helper methods or pass it to standard Java/Kotlin/Scala functions—the #{...} token will be treated as a literal string.Wrong:
queryParam("lat", Integer.parseInt("#{latitude}")) // parseInt receives the literal string "#{latitude}"
Right:
queryParam("lat", session -> session.getInt("latitude")) // use a function instead

Syntax

EL expressions use the #{attributeName} syntax. The attribute name must exactly match a key stored in the virtual user’s Session.
// Direct attribute access
"#{username}"

// Access an element by index (0-based, or negative to count from the end)
// Works with arrays, Java List, Scala Seq, and Scala Product
"#{items(0)}"    // first element
"#{items(-1)}"   // last element

// Access a nested field by key
// Works with Java Map, Java POJO, Java records, Scala Map, and Scala case class
"#{user.email}"
"#{address.city}"
The legacy ${} syntax (e.g., ${foo}) is obsolete and has been replaced by #{} to avoid clashing with Kotlin and Scala string interpolation. Always use #{}.

Built-in Functions

EL provides a rich set of built-in functions that can be appended to any attribute reference.

Collection Functions

// Number of elements in the collection
// Works with arrays, Java Collection, Java Map, Scala Iterable and Product
"#{items.size()}"

// A random element from the collection
// Works with arrays, Java Collection, Java List, Scala Seq and Product
"#{items.random()}"

Existence Checks

// true if the session contains the attribute
"#{foo.exists()}"

// true if the session does NOT contain the attribute
"#{foo.isUndefined()}"

String and Formatting Functions

// Encode as a JSON value (wraps Strings in double quotes, handles null)
"#{payload.jsonStringify()}"

// Decode HTML entities in a string
"#{htmlBody.htmlUnescape()}"

Date and Time Functions

// System.currentTimeMillis() at the moment of evaluation
"#{currentTimeMillis()}"

// ZonedDateTime.now() formatted with a java.time.format.DateTimeFormatter pattern
"#{currentDate(yyyy-MM-dd'T'HH:mm:ss)}"

Random Value Generators

// Random UUID (fast, not cryptographically secure)
"#{randomUuid()}"

// Random UUID (cryptographically secure via java.util.UUID#randomUUID)
"#{randomSecureUuid()}"
Double literals in randomDouble must match the format -?\\d+\\.\\d+ (e.g., 0.34 is valid; .34 and 2. are not). For very large or very small ranges, the result may appear in scientific notation.

Composing EL Expressions

EL built-in functions can be chained and combined:
// First element of the first list inside attribute "foo"
"#{foo(0)(0)}"

// Random element from the list stored under key "list" in the map "foo"
"#{foo.list.random()}"

Escaping

To prevent #{ from being interpreted as an EL expression, prepend it with a backslash:
#{foo}     → resolves the attribute "foo"
\#{foo}    → literal string "#{foo}"
\\#{foo}   → literal backslash "\" + resolved value of "foo"
\\\#{foo}  → literal string "\#{foo}"

Usage in Requests

EL strings can be used anywhere Gatling SDK methods accept a String or Expression[String]:
http("search")
  .get("/search")
  .queryParam("q", "#{keyword}")
  .queryParam("page", "#{page}")

Limitations

EL is intentionally simple. For computations that go beyond attribute lookup and the built-in functions listed above, use a Session function instead:
// EL can't do arithmetic — use a function
queryParam("nextPage", session -> session.getInt("page") + 1)

Build docs developers (and LLMs) love