【问题标题】:Robot FrameWork:: Return a Value before Keyword endsRobot FrameWork:: 在关键字结束前返回一个值
【发布时间】:2018-06-24 17:45:48
【问题描述】:

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

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 Keyword if '${Is_Checkbox_Selected}'== 'True' Return True Log somemsg

【问题讨论】:

  • 刚刚引起我注意的东西 - Run keyword and return status 返回一个真正的 python True/False - 一个布尔数据类型。因此,您不必比较它们的字符串表示形式,最好将其作为布尔值进行:Run Keyword if ${Is_Checkbox_Selected}
  • 是的,没错

标签: python robotframework


【解决方案1】:

关键字结束前返回值的关键字是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 都必须是大写字母,以便框架选择它们作为保留关键字。

【讨论】:

    猜你喜欢
    • 2011-11-26
    • 1970-01-01
    • 2017-06-05
    • 2016-11-21
    • 2015-09-09
    • 2022-08-18
    • 1970-01-01
    • 1970-01-01
    • 2016-09-17
    相关资源
    最近更新 更多