ReplaceWithVAR¶
Replace Set Variable, Create Dictionary, Create List and Catenate keywords with VAR.
Enabling the transformer
ReplaceWithVAR is not included in default transformers, that’s why you need to call it with --transform explicitly:
robotidy --transform ReplaceWithVAR src
Or configure enabled parameter:
robotidy --configure ReplaceWithVAR:enabled=True
*** Keywords ***
Custom Keyword
${var} Set Variable value
Set Suite Variable ${SUITE_VAR} ${var}
${list} Create List ${var} second value
${string} Catenate join with spaces
*** Keywords ***
Custom Keyword
VAR ${var} value
VAR ${SUITE_VAR} ${var} scope=SUITE
VAR @{list} ${var} second value
VAR ${string} join with spaces separator=${SPACE}
Variable scope¶
VAR syntax supports setting the scope of the variable with scope= parameter. It’s equivalent of the following
keywords:
Set Local Variable
Set Task Variable
Set Test Variable
Set Suite Variable
Set Global Variable
Other keywords such as Set Variable, Catenate, Create Dictionary and Create List create variable in the
local scope. Local scope is omitted by default but can be explicitly set by using explicit_local parameter.
Set Suite Variable with children=True is ignored as it is not possible to have the same behaviour with VAR.
*** Keywords ***
Custom Keyword
${var} Set Variable value
Set Local Variable ${local_variable} value
Set Task Variable ${task_variable} value
Set Test Variable ${test_variable}
Set Suite Variable ${suite_variable} value with ${value}
Set Suite Variable ${suite_variable} value with ${value} children=${True} # ignored
Set Global Variable ${global_variable} value
*** Keywords ***
Custom Keyword
VAR ${var} value
VAR ${local_variable} value
VAR ${task_variable} value scope=TASK
VAR ${test_variable} ${test_variable} scope=TEST
VAR ${suite_variable} value with ${value} scope=SUITE
Set Suite Variable ${suite_variable} value with ${value} children=${True} # ignored
VAR ${global_variable} value scope=GLOBAL
*** Keywords ***
Custom Keyword
VAR ${var} value scope=LOCAL
VAR ${local_variable} value scope=LOCAL
VAR ${task_variable} value scope=TASK
VAR ${test_variable} ${test_variable} scope=TEST
VAR ${suite_variable} value with ${value} scope=SUITE
Set Suite Variable ${suite_variable} value with ${value} children=${True} # ignored
VAR ${global_variable} value scope=GLOBAL
Catenate¶
Catenate keyword will be replaced with VAR. Separator is set using separator= parameter. Catenate keywords
can be ignored by setting replace_catenate parameter to False.
Create Dictionary¶
Create Dictionary keyword will be replaced with VAR. Variable name will change from ${name} to &{name}
to reflect the type of the variable. Create Dictionary keywords can be ignored by setting
replace_create_dictionary parameter to False.
Create List¶
Create List keyword will be replaced with VAR. Variable name will change from ${name} to @{name}
to reflect the type of the variable. Create List keywords can be ignored by setting
replace_create_list parameter to False.
Set Variable If¶
Set Variable If keyword will be replaced with IF and VAR. If value in ELSE branch is not set, implicit
${None} value will be used. Keywords with dynamic values (@{values}) are ignored since they may contain
ELSE IF and ELSE branches that should be also converted. Set Variable If keywords can be ignored by setting
replace_set_variable_if parameter to False.
*** Keywords ***
Custom Keyword
${var} = Set Variable If ${rc} > 0 whatever
${var}= Set Variable If ${rc} == 0 zero
... ${rc} > 0 greater than zero less then zero
${var} Set Variable If ${condition} @{items} # ignored
*** Keywords ***
Custom Keyword
IF ${rc} > 0
VAR ${var} whatever
ELSE
VAR ${var} ${None}
END
IF ${rc} == 0
VAR ${var} zero
ELSE IF ${rc} > 0
VAR ${var} greater than zero
ELSE
VAR ${var} less then zero
END
${var} Set Variable If ${condition} @{items} # ignored