Robotframework 在Robot Framework中增加值时出错
我得到以下错误: 找不到名为“11=”的关键字Robotframework 在Robot Framework中增加值时出错,robotframework,variable-assignment,increment,Robotframework,Variable Assignment,Increment,我得到以下错误: 找不到名为“11=”的关键字 如果,则在运行关键字中不能有变量赋值-顾名思义,它只用于运行关键字,不支持赋值(它将变量视为必须运行的另一个关键字)。因此,错误-框架用它的值(11)替换了${TIME},并尝试执行它。 在版本4.0中,它支持适当的IF/ELSE块,但此限制不适用: *** Settings *** Library DateTime *** Test Cases *** Test title ${TIME}= get current date re
如果,则在
运行关键字中不能有变量赋值-顾名思义,它只用于运行关键字,不支持赋值(它将变量视为必须运行的另一个关键字)。因此,错误-框架用它的值(11)替换了${TIME}
,并尝试执行它。
在版本4.0中,它支持适当的IF/ELSE
块,但此限制不适用:
*** Settings ***
Library DateTime
*** Test Cases ***
Test title
${TIME}= get current date result_format=%H
RUN KEYWORD IF
... int(${TIME})%2==0
... ${TIME}= catenate SEPARATOR= ${TIME} :00
... ELSE
... ${TIME}= Evaluate int(${TIME})+1
... ${TIME}= catenate SEPARATOR= ${TIME} :00
log to console ${TIME}
同时,您可以使用另一种方法来解决此问题—使用设置变量If
。如果它是有条件的,但只接受值,则运行关键字是非常简单的。
框架中有一个功能,您可以就地进行计算(严格地说,是调用方法),我们将使用该功能,用1增加值:
Test title
${TIME}= get current date result_format=%H
IF int(${TIME})%2==0
${TIME}= catenate SEPARATOR= ${TIME} :00
ELSE
${TIME}= Evaluate int(${TIME})+1
${TIME}= catenate SEPARATOR= ${TIME} :00
END
log to console ${TIME}
Test title
${TIME}= get current date result_format=%H
${TIME}= Convert To Integer ${TIME} # to be sure it's type is this, I haven't checked what the keyword returns
${TIME}= Set Variable If ${TIME}%2==0 ${TIME}:00
... ${TIME + 1}:00 # this is the ELSE block
log to console ${TIME}