布尔型参数

Robot Framework的标准库中有很多关键字接受一个布尔型的值, true或false. 如果参数是字符串的形式提供, 则如果该字符串是空的, 或者转为小写后等于 falseno, 则表明该值是false. 其它的字符串一律视为true. 如果参数是其它类型, 则这些值按照 Python语言的规则 来判断.

关键字还可以接受除了falseno 之外的其它特殊字符串为false. 例如, 内置_ 关键字 Should Be True, 如果它的 values 参数被传递字符串 no values, 则视作false.

  1. *** Keywords ***
  2. True examples
  3. Should Be Equal ${x} ${y} Custom error values=True # Strings are generally true.
  4. Should Be Equal ${x} ${y} Custom error values=yes # Same as the above.
  5. Should Be Equal ${x} ${y} Custom error values=${TRUE} # Python `True` is true.
  6. Should Be Equal ${x} ${y} Custom error values=${42} # Numbers other than 0 are true.
  7.  
  8. False examples
  9. Should Be Equal ${x} ${y} Custom error values=False # String `false` is false.
  10. Should Be Equal ${x} ${y} Custom error values=no # Also string `no` is false.
  11. Should Be Equal ${x} ${y} Custom error values=${EMPTY} # Empty string is false.
  12. Should Be Equal ${x} ${y} Custom error values=${FALSE} # Python `False` is false.
  13. Should Be Equal ${x} ${y} Custom error values=no values # Special false string in this context.

注意, 在Robot Framework 2.9 之前的版本中, 布尔值的判断并不统一. 有的关键字遵守上面的规则, 但是有的简单地把所有非空字符串(包括falseno)都视作true.