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.
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