Dan G
Dan G

Reputation: 396

Robot Framework Multiple Statements in If Condition

I am new to Robot Framework and am trying to figure out how to have multiple statements associated with an If condition.

The basic pre-code counts entries in an array WORDS, and assigns the value to length.

${length}=    Get length    ${WORDS}

Next I want to do a simple check for the size of the array (should have 10 items).

${status}=    Set Variable If   ${length} == 10    TRUE    FALSE

Now I want to log the result and pass or fail the test case.

Run Keyword If    $status == "TRUE"
...  Log    ${status}
...  ELSE
...  Log    ${status}

Run Keyword If     $status != "TRUE"
...  FAIL   Values do not match

I want to combine the ELSE + logging the status + failing the test case, but can not seem to figure it out. In C programming, I would simply brace the statements between { } and be ok.

In Robot Framework, I have tried 'Run keywords' but with no luck.

...   ELSE   Run keywords 
...     Log    ${status}      
...     FAIL   Values Do Not Match       

I hope there is a way to accomplish this. Appreciate any input.

Upvotes: 0

Views: 8262

Answers (3)

RahulKasana
RahulKasana

Reputation: 9

    Set Test Variable    ${temp}    rxu
    Run Keyword if    '${temp}'=='rxu'
    ...    Run Keywords
    ...    Log To Console    this is one
    ...    Log To Console    This is two
    ...    ELSE    Run Keyword    Log To Console    another block

Upvotes: -2

Bryan Oakley
Bryan Oakley

Reputation: 385970

Using "Run keywords" is the correct solution. However, in order to run multiple keywords you must separate keywords with a literal AND:

...    ELSE     run keywords
...    log    ${status}
...    AND    FAIL   Values Do Not Match

Upvotes: 4

soyacz
soyacz

Reputation: 457

You can create keyword with log and fail keywords and pass status as argument, then just use this keyword after ELSE statement.

Or use run keywords like you did, but add AND statement before FAIL (read more here: http://robotframework.org/robotframework/latest/libraries/BuiltIn.html#Run%20Keywords)

Or consider adding ${status} to Fail message: Fail Values Do Not Match. Status: ${status}

Upvotes: 0

Related Questions