考虑以下示例:
*** Variables ***
${myVaraible}= ${None}
*** Test cases ***
MyTest
A Keyword That May Or May Not Set myVariable
IF "${myVariable}" != ${None}
A Keyword
ELSE
Another Keyword
END
我的问题是,即使不重新分配
${myVariable}
,布尔表达式"${myVariable}" != ${None}
仍然为假,并且将执行ELSE分支而不是IF分支。
那么,根据变量是否为
${None}
执行不同的关键字的 if else 语句的正确编写方法是什么呢?
看起来,在引号中写入
"${myVariable}"
会将${myVariable}
的值转换为字符串,在本例中为'"None"'
,这当然不等于${None}
。
检查变量是否为 None 的正确方法是这样的:
IF ${myVariable} is None
A Keyword
ELSE
Another Keyword
END
或者,检查变量是否不是 None:
IF ${myVariable} is not None
A Keyword
ELSE
Another Keyword
END