0

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.

3 Answers 3

4

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
Sign up to request clarification or add additional context in comments.

Comments

0

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}

Comments

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

2 Comments

While this code snippet may solve the question, including an explanation really helps to improve the quality of your post. Remember that you are answering the question for readers in the future, and those people might not know the reasons for your code suggestion.
Doesn’t work without AND (see stackoverflow.com/a/33939585/1548776).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.