Expression Language

Use the Gatling Expression Language to generate dynamic parameters

Most Gatling DSL methods can be passed Gatling Expression Language (EL) Strings.

This is a very convenient feature to pass dynamic parameters.

Syntax

Gatling EL uses a #{attributeName} syntax to define placeholders to be replaced with the value of the matching attributeName attribute’s value stored in the virtual user’s Session, eg: request("page").get("/foo?param=#{bar}").

// direct attribute access
"#{foo}"

// access by index
// supports arrays, Java List, Scala Seq and Product
"#{foo(n)}"
  
// access by key
// supports Java Map, Java POJO, Java records, Scala Map and Scala case class
"#{foo.bar}"

Built-in Functions

Gatling EL provide the following built-in functions:

// collection size
// supports arrays, Java List, Scala Seq and Product
"#{foo.size()}"

// collection size
// supports arrays, Java Collection, Java Map, Scala Iterable and Product
  
// collection random element
// supports arrays, Java Collection, Java List, Scala Seq and Product
"#{foo.random()}"
  
// true if the session contains a `foo` attribute
"#{foo.exists()}"
  
// true if the session doesn't contains a `foo` attribute
"#{foo.isUndefined()}"
  
// properly formats into a JSON value (wrap Strings with double quotes, deal with null)
"#{foo.jsonStringify()}"
  
// System.currentTimeMillis
"#{currentTimeMillis()}"
  
// new java.util.Date() formatted with a java.text.SimpleDateFormat pattern
"#{currentDate(<pattern>)}"
  
// unescape an HTML String (entities decoded)
"#{foo.htmlUnescape()}"

You can combine different Gatling EL builtin functions, eg:

// return first element of the first list in `foo`
"#{foo(0)(0)}"

// return a random element from the List associated with key `list` in the Map `foo`
"#{foo.list.random()}"

Escaping

To prevent "#{" from being interpreted by the EL compiler, add a \\ before it. "\\#{foo}" will be turned into "#{foo}".

If you want a $ before the placeholder, add another $. Assuming the session attribute foo holds "FOO", "$$${foo}" will be turned into "$FOO".

This can go on and on. In general, if there are 2n-1 $ characters before ${ – an even number of $ characters totally – there will be n $ before { in the final string; if there are 2n $ before ${ – an odd number totally – there will be n $ before the placeholder.

Edit this page on GitHub