Skip to content

If Action

The If Action allows you to control whether the actions below it (its children) are run or not.

Warning

Be careful since only children of the If Action will be impacted. Use the indentation to check that your If Action is correctly setup.

A common example is to control if the login is ok before running the rest of the script. This can be achieved in combination with a Regexp Action: If Action

Parameter name Description Required
Name Descriptive name for this container which is indicated in the bench report. The name is not required, but it is a good habit to name your containers so that you can differentiate them in your bench reports. No
Condition This condition must evaluate to "true" in order to process the children of the If action. See below for more details. Yes

Conditions

The if Logic Actions can contain condition expressions. These expressions are composed of:

  • variable references like ${my_variable},
  • constants such as the "test" string of the number 42,
  • comparison operators like < or >,
  • boolean operations && or ||.

E.g. you declared two variables count and categoryId, you may use the condition: ${count} < 10 && "${categoryId}" == "abc". This condition will be true when count value is strictly inferior to 10 AND categoryId is equal to the "abc" word.

Tip

If you compare numeric values simply write ${myNumber} >= 100. If you compare strings, you must enclose your variable in quotes: "${myString}" == "sampleString".

Comparison operators

Operator symbol Description
== Left value must be equal to right value
!= Left value must be different than right value
<= Left value must be inferior or equal to right value
>= Left value must be superior or equal to right value
< Left value must be inferior to right value
> Left value must be superior to right value

Boolean operators

Operator symbol Description
&& Left value AND right value must be true
|| Left value OR right value must be true

Common mistakes

Condition Should be
${cart_status} != "PROCESSING" "${cart_status}" != "PROCESSING"
${loginOK} != "NotFound" "${loginOK}" != "NotFound"
${myvar} <= "10" ${myvar} <= 10
"${loginOK}" != "Notfound" "${loginOK}" != "NotFound" with an uppercase 'F'
${login_${count}} != "NotFound" ${_V(login${count})} != "NotFound"
${counter}<=5 ${__javaScript(vars.get("counter")<=5)}