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.
END Use Run Keyword If in Robot Framework Run Keyword If ${True} Log This line IS executed. Run Keyword If ${False} Log This line is NOT executed. Use Run Keyword Unless in Robot Framework Run Keyword Unless ${True} Log This line is NOT executed. Run Keyword Unless ${False} Log This line IS executed.
Pseudocode of an if Statment: An if Statement allows your robot to make a decision. When your robot reaches an if Statment in the program, it evaluates the condition contained between the parenthesis. If the condition is true, any commands between the braces are run.
There are three types of variables supported in robot framework − scalar, list and dictionary.
Breaking out of the for loop using BREAKUsing an IF condition and BREAK , we can stop the execution of the for loop and have our program continue after it.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With