【发布时间】:2016-05-03 02:05:07
【问题描述】:
我很困惑,因为NameError 失败了:
${val} = Execute Javascript return sessionStorage.isMatching
Should Be True ${val}
日志输出为:
INFO Executing JavaScript:
INFO ${val} = true
KEYWORD BuiltIn . Should Be True ${val}
TRACE Arguments: [ 'true' ]
FAIL Evaluating expression 'true' failed: NameError: name 'true' is not defined
这也不起作用:
Should Be True ${val} == true --> Evaluating expression 'true == true' failed: NameError: name 'true' is not defined
Should Be True ${val} == 'true' --> Evaluating expression 'true == 'true'' failed: NameError: name 'true' is not defined
Should Be True ${val} == "true" --> Evaluating expression 'true == "true"' failed: NameError: name 'true' is not defined
阅读文档后,我了解到底层 python 不会将 JS true 评估为 true。然后我尝试在 JS 中将布尔值转换为字符串:
${val} = Execute Javascript return sessionStorage.isMatching.toString()
但我又收到了NameError。
我知道的唯一方法是这看起来很糟糕(因为我必须明确地将布尔值转换为布尔值):
${val} = Execute Javascript return sessionStorage.isMatching
${bool} = Convert To Boolean ${val}
Should Be True ${bool}
有没有更好的方法在 RF 或 JS 中对此进行评估?
版本:
Python 2.7.8
机器人框架 3.0
【问题讨论】: