Use of "If statement" in robot framework

user3068846 picture user3068846 · Jun 24, 2015 · Viewed 36.3k times · Source

How can we use if statement in robot framework. I would like to execute keyword only if it satisfies certain condition else it execute other code.

Answer

Bryan Oakley picture Bryan Oakley · Jun 24, 2015

This is described in the Robot Framework User Guide under the section Conditional Execution, where it mentions Run Keyword If and Run Keyword Unless among other solutions. Documentation for these can be found in the documentation for the BuiltIn keyword library.

Here is a brief example:

*** Test cases ***
| Example
| | ${result}= | Set variable | 42
| | Run keyword if | "${result}" == "42"
| | ... | log | the result is 42
| | ... | ELSE 
| | ... | log | the result is NOT 42