JMeter contains a built-in component that can assist in controlling the logical flow of a load test based on internal conditions. Using the If Controller, conditional logic can be set up to either run once for a group of elements, or optionally for each element within a set. Only if the specified condition is “true” will items within the If Controller be executed.
Once added to a test plan, the If Controller acts as a container for one or more child components. These can be sampler elements such as HTTP Requests, or other logical components. Additionally, it is possible to nest If Controllers to create more complicated, branching test logic:
Evaluating Conditions
Subscribing to classic “if-then” logic, flow control is evaluated as “true
” or “false
”. This primarily occurs in one of two ways. JMeter variables can hold boolean values and be referenced directly as the condition, using standard ${…} notation. The second method afforded by the If Controller is evaluating a snippet of JavaScript as “true
” or “false
”.
For performance reasons, it is strongly recommended that Java Expression Language (JEXL) be used by invoking the jexl3()
method. This can be accomplished via the JMeter special function, i.e., ${__jexl3()}
. You do have the option to use JavaScript by unchecking the “Interpret Condition as Variable Expression” setting. However, while this can be more flexible there is a severe performance penalty as alerted when this setting is unchecked:
Handling Child Elements
There are two behaviors to select from when evaluating child elements. The default behavior is to evaluate the condition of the If Controller once for the entire set of children. This will result in an all-or-nothing pattern of execution. Optionally, you may tick the “Evaluate for all children” checkbox which will have the effect of running the condition for each child element and only executing on those occurrences where the result is “true
”.
Did you know that RedLine13 offers a full-featured, time-limited free trial? Sign up now, and start testing today!