'IF block in Robot Framework
Can we have a block of keywords to be executed within a IF part and optionally with ELSE/ELSE IF part ?. It can be like something below:
Run keyword If ${x} == "Simple"
Keyword1 [arg1] [arg2]
Keyword2 [arg3]
Keyword3 [arg4] [arg5]
ELSE
Keyword4 [arg6]
END IF
Solution 1:[1]
Run Keyword If doesn't support calling multiple keywords, but you can run the keyword Run Keywords which will let you run multiple keywords.
For example:
*** Test Cases ***
| Example of running multiple keywords with "Run keyword if" and "Run keywords"
| | ${x}= | Set variable | Simple
| | Run keyword if | "${x}" == "Simple" | Run keywords
| | ... | log to console | this is keyword one
| | ... | AND | log to console | this is keyword two
| | ... | ELSE
| | ... | log to console | this is keyword three
Of course, you can always just create additional keywords:
*** Keywords ***
| Handle the simple case
| | log to console | this is keyword one
| | log to console | this is keyword two
| Handle the complex case
| | log to console | this is keyword three
*** Test Cases ***
| Example of using separate keywords for "Run keyword if"
| | ${x}= | Set variable | Simple
| | Run keyword if | "${x}" == "Simple"
| | ... | Handle the simple case
| | ... | ELSE
| | ... | Handle the complex case
Solution 2:[2]
Run keyword If ${x} == "Simple" Run Keywords
Keyword1 [arg1] [arg2]
AND
Run Keyword Keyword2 [arg3]
AND
Run Keyword Keyword3 [arg4] [arg5]
ELSE
Keyword4 [arg6]
END IF
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | |
| Solution 2 | user18240881 |
