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

时间:2018-01-16 04:27:35

标签: 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

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

另外..如何做以下动作..(即想要返回并打印一些消息)

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

1 个答案:

答案 0 :(得分:4)

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

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

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

注意这个案例 - ELSE和AND必须用大写字母表示框架才能选择保留关键字。

相关问题