Robot FrameWork::在关键字结束前返回一个值

bbk*_*bbk 2 python robotframework

有没有办法根据条件返回值

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
Run Code Online (Sandbox Code Playgroud)

不确定这是否可以实现。如果不是,可能的方法是什么?

另外..如何做下面的动作..(即想返回并打印一些味精)

如果 '${Is_Checkbox_Selected}'== 'True' 则运行关键字返回 True Log somemsg

Tod*_*kov 6

在关键字结束之前返回值的关键字是Return From Keyword; 还有速记条件变体Return From Keyword If(这两个关键字都在 Robot Framework 2.8 -文档中引入)。

要记录消息然后返回,请使用Run Keywords以下命令链接两个命令:

Run Keyword if  '${Is_Checkbox_Selected}'== 'True'  Run Keywords  Log somemsg    AND    Return From Keyword   True
...   ELSE    Return From Keyword    False
Run Code Online (Sandbox Code Playgroud)

注意大小写 - ELSE 和 AND 都必须是大写字母,框架才能将它们选为保留关键字。