在Robot Framework中使用多个操作的If-Condition

时间:2017-01-24 06:44:34

标签: python-2.7 testing automated-tests robotframework

我想在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-Condition和多个动作

5 个答案:

答案 0 :(得分:3)

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

请通过以下链接:

IF ELSE in robot framework with variables assignment

答案 1 :(得分:1)

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

答案 2 :(得分:1)

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

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

答案 3 :(得分:0)

请参阅以下关键字:

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

答案 4 :(得分:0)

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