比较Robot Framework测试用例中的FALSE表达式

时间:2017-06-26 11:19:49

标签: robotframework

我有否定bool变量或将FALSE与bool变量进行比较以执行Run Keyword If

我的代码是

Test Case
    ${isExist}=  Run Keyword And Return Status    Element Should Be Visible    ${element_Id}
    Run Keyword If     ${isExist} == false    click element ${cancelbtn}

我在这里遇到了运行时错误

  

评估表达式' True和'失败:SyntaxError:意外的EOF   解析时(第1行)

我也尝试了以下比较

  • ${isExist} == 'false'
  • '${isExist}' == 'false'
  • ${isExist} == ${false}
  • '${isExist}' == '${false}'
  • !${isExist}

注意:log to console ${isExist} - 它在控制台窗口中记录相应的布尔值。

1 个答案:

答案 0 :(得分:5)

如果${isExist}是布尔值,您可以使用not

Run Keyword If     not ${isExist}     ...

您还可以与${FALSE}${TRUE}进行比较:

Run Keyword If     ${isExist} is ${FALSE}    ...
Run Keyword If     ${isExist} is not ${TRUE}  ... 

您说${isExist} == ${false}不起作用,但如果{isExist}确实是布尔值False,那么它将会起作用。

注意:${FALSE}${TRUE}是由robot定义的变量。它们在机器人框架用户指南中标题为Boolean and None/null variables的部分的文档中简要提及。

相关问题