Conditions

Learn about conditional statements that Gatling provides.

In the previous lesson, we learned about the different loops that Gatling offers. In this lesson, we will learn about the different conditional statements offered by Gatling.

Gatling provides various conditional statements, such as doIf, doIfEquals, doIfOrElse, doIfEqualsOrElse, doSwitch, doSwitchOrElse, randomSwitch, randomSwitchOrElse, uniformRandomSwitch, and roundRobinSwitch. Let’s see them in more detail.

doIf

You can use the doIf method for executing a specific chain of actions only when some condition is satisfied.

condition will be looked up in the user session or any other value that evaluates to Boolean.

doIf("${condition}") {
  exec(...)
}
doIf(session => session("condition").as[Boolean]) {
  exec(...)
}

A sample scenario:

Get hands-on with 1200+ tech skills courses.