【问题标题】:If-Condition with multiple actions in Robot Framework在 Robot Framework 中具有多个操作的 If-Condition
【发布时间】:2017-06-08 20:47:44
【问题描述】:

我想在 Robot Framework 中使用 If-Condition 和多个操作

${x}    Set Variable    5   
Run Keyword If  ${x} == 5       
... ${Test1} =  Set Variable    MyName
... ${Test2} =  Set Variable    MyLastName
... Else        
... ${Test1} =  Set Variable    MyAddress
... ${Test2} =  Set Variable    MyTelephone

但它不起作用 错误显示失败:未找到变量“${Test1}”。 能否请您告诉我有关使用多个操作的 IF 条件

【问题讨论】:

    标签: python-2.7 testing automated-tests robotframework


    【解决方案1】:

    您可以使用“运行关键字”关键字在 IF 条件下执行多个操作

    请通过以下链接:

    IF ELSE in robot framework with variables assignment

    【讨论】:

    • 哦,我的。 RF 家伙真的认为这种语法比原始 Python 语法更好吗?为什么不直接用python写测试用例呢? IMO,这要容易得多。
    • @Jcyrss 我想条件语句是事后才添加的,必须硬塞进现有的语法中。请注意,“If”必须使用小写“f”,而“ELSE”必须全部大写。是的,符合语法方案,但是......呃......“非常规”。到目前为止,我很高兴几年前承诺的 WHILE 声明尚未超过我的方式。
    【解决方案2】:

    您必须使用一个自定义关键字覆盖这两个操作,然后调用 Run Keyword If 或调用关键字 Set Variable If 两次或将此类逻辑写入 python (jython...) 库。

    【讨论】:

      【解决方案3】:

      使用“运行关键字”时请注意“与”;还要确保使用标签。

      Run Keyword If  <condition1>  <action1>
          ...   ELSE IF  <condition1>
          ...   Run Keywords
          ...   <action1>
          ...   AND  <action2>
      

      【讨论】:

        【解决方案4】:
        Set Test Variable    ${temp}    rxu
        Run Keyword if    '${temp}'=='rxu'
        ...    Run Keywords
        ...    Log To Console    this is one
        ...    AND    Log To Console    This is two
        ...    ELSE    Run Keyword    Log To Console    another block
        

        【讨论】:

          【解决方案5】:

          参考以下关键字:

          Run Keyword If  ${x} == 5     Set Variable    MyName
          Run Keyword If  ${x} == 1     Set Variable    LastName
          

          或者

          Run Keyword If  ${x} == 5     Set Variable    MyName
          ... ELSE IF  ${x} == 2        Set Variable    MyName
          ... ELSE IF  ${x} == 3        Set Variable    Middle Name
          

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 1970-01-01
            • 2023-03-10
            • 2014-07-14
            • 1970-01-01
            • 2015-05-18
            • 2017-07-05
            • 2023-03-13
            • 1970-01-01
            相关资源
            最近更新 更多