2
votes

Is there way to return Value based on condition

Obtain The Status Of CheckBox   
    [Arguments]  ${item}
    ${Is_Checkbox_Selected}=    Run Keyword And Return Status    Checkbox Should Be Selected    //*[@id="ctl00_PageBody_RolesList"]/tbody/tr/td/label[normalize-space(text())='${item}']/preceding-sibling::input
    Run Keyword if   '${Is_Checkbox_Selected}'== 'True'   Return  True   #Todo: how to do more than one action here
    ...   Else  Return  False

Not Sure if this can be achieved. If NOT what are the possible ways?

Also .. how to do below action..( i.e. Wanted to return and print some msg)

Run Keyword if '${Is_Checkbox_Selected}'== 'True' Return True Log somemsg

1
Something that just caught my attention - Run keyword and return status returns a real python True/False - a boolean datatype. So you don't have to compare their string representation, it's even better to do it as booleans: Run Keyword if ${Is_Checkbox_Selected} - Todor Minakov
yup that is correct - bbk

1 Answers

7
votes

The keyword to return a value before the end of a keyword is Return From Keyword; there is also the shorthand conditional variant Return From Keyword If (both keywords were introduced in Robot Framework 2.8 - documentation).

To log a message, and then return, chain the two commands with Run Keywords:

Run Keyword if  '${Is_Checkbox_Selected}'== 'True'  Run Keywords  Log somemsg    AND    Return From Keyword   True
...   ELSE    Return From Keyword    False

Pay attention to the case - both ELSE and AND must be in capital letters for the framework to pick them as reserved keywords.