如果是机器人框架中的Else-if

时间:2015-01-30 05:21:16

标签: python-2.7 testing if-statement automated-tests robotframework

我想通过使用else if来获取关键字的值。

示例:

String text = ""  
If variable > 5
   text = "one";
else if variable <5
   text = "two";
else
   text = "three";

在机器人框架中

我使用代码

${txt}    Set Variable
${txt}=    Run Keyword If    ${length} > 5    Some Keyword
\    ELSE IF    ${length} < 5    Some Keyword
\    ELSE    Some Keyword
Log       ${txt}

错误!!!

In Keyword ELSE IF  ;  Keyword name cannot be empty

3 个答案:

答案 0 :(得分:9)

只需在ELSE IF关键字之前的第一个单元格中添加三个点(...)

${txt}    Set Variable
${txt}=    Run Keyword If    ${lenght} > 5    Some Keyword
...    ELSE IF    ${lenght} < 5    Some Keyword
...    ELSE    Some Keyword
Log       ${txt}

答案 1 :(得分:0)

使用Robot Framework的switch语句版本对此进行编码的另一种方法是:

*** Variables ***    
String  ${text} =  ""

*** Keywords ***
${text} =  Set Variable If
...  ${variable} > 5  one
...  ${variable} < 5  two
...  ${variable} = 5  three

使用“运行关键字If”和“运行关键字除非”可能还有其他方法。

答案 2 :(得分:0)

自机器人 4.0 以来,本机 IF else 支持可用。您可以参考以下示例:

IF  '${status}' == 'true'
    ${i}  Set Variable  10
    log to console  inside if
ELSE IF  '${status}' == 'false'
    ${i}  Set Variable  20
    log to console  inside else if
ELSE
    ${i}  Set Variable  30
    log to console  inside else
END