Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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
like image 259
Kamil Avatar asked May 19 '26 19:05

Kamil


1 Answers

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
like image 141
Bryan Oakley Avatar answered May 28 '26 09:05

Bryan Oakley