Python 2.7 机器人框架中的If-Else-If
我希望使用else if从关键字中获取值 例如:Python 2.7 机器人框架中的If-Else-If,python-2.7,testing,if-statement,automated-tests,robotframework,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 ${lenght} > 5 Some
String text = ""
If variable > 5
text = "one";
else if variable <5
text = "two";
else
text = "three";
只需在第一个单元格中添加三个点(…),然后再添加关键字
${txt} Set Variable
${txt}= Run Keyword If ${lenght} > 5 Some Keyword
... ELSE IF ${lenght} < 5 Some Keyword
... ELSE Some Keyword
Log ${txt}
${txt}集变量
${txt}=如果${lenght}>5某个关键字,则运行关键字
... 如果${lenght}<5,则使用其他关键字
... 还有一些关键词吗
日志${txt}
使用Robot Framework版本的switch语句对此进行编码的另一种方法是:
*** Variables ***
String ${text} = ""
*** Keywords ***
${text} = Set Variable If
... ${variable} > 5 one
... ${variable} < 5 two
... ${variable} = 5 three
***变量***
字符串${text}=“”
***关键词***
${text}=设置变量,如果
... ${variable}>5一
... ${variable}<5二
... ${variable}=5三
可能还有其他方法使用Run关键字If和Run关键字except。因为自robot 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
该解决方案适用于运行关键字,但如果在ELSE IF或ELSE中声明了变量,则返回错误。例如:如果在ELSE中声明了类似${a}=1的变量,并且在对控制台${a}执行日志操作时返回“变量${a}未找到”
*** Variables ***
String ${text} = ""
*** Keywords ***
${text} = Set Variable If
... ${variable} > 5 one
... ${variable} < 5 two
... ${variable} = 5 three
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