Conditions
Explore the various conditional statements Gatling offers to create dynamic performance test scripts. Understand how to use doIf, doIfEquals, doSwitch, randomSwitch, and others to control execution flow based on session conditions and create realistic testing scenarios.
We'll cover the following...
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: ...