- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我很困惑,因为 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 中将 bool 值转换为字符串:
${val} = Execute Javascript return sessionStorage.isMatching.toString()
但是我又遇到了一个NameError
。
我知道的唯一方法是这看起来很糟糕(因为我明确必须将 bool 值转换为 bool 值):
${val} = Execute Javascript return sessionStorage.isMatching
${bool} = Convert To Boolean ${val}
Should Be True ${bool}
有没有更好的方法,在 RF 或 JS 中对此进行评估?
版本:
Python 2.7.8
Robotframework 3.0
最佳答案
您从 javascript 返回的是文字字符串 'true'
。要在表达式中使用它,您必须引用它:
Should be true '${val}` == 'true'
您收到错误 NameError: name 'true' is not defined
的原因是机器人在计算表达式之前执行字符串替换。
换句话说,机器人中的这个表达式:
should be true ${val} == 'true'
... 与您在 python 中输入的内容相同:
if true == 'true':
...
Python 看到 true
,尝试查找名为 true
的变量的值,但没有找到任何此类变量。因此,您会得到 NameError
。
您可以在 BuiltIn library 的文档中找到对此的描述(强调我的):
When a variable is used in the expressing using the normal ${variable} syntax, its value is replaces before the expression is evaluated. This means that the value used in the expression will be the string representation of the variable value, not the variable value itself. This is not a problem with numbers and other objects that have a string representation that can be evaluated directly, but with other objects the behavior depends on the string representation. Most importantly, strings must always be quoted, and if they can contain newlines, they must be triple quoted.
关于javascript - Robotframework:如何评估从 Javascript 调用返回的 bool 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35015039/
有人可以解释我如何使用与数据驱动测试用例相关的可选关键字参数的默认值吗? 正如您在我的示例中看到的,在某些情况下并非所有默认值都被使用: *** Test Cases *** | testArgs |
我正在尝试做这个练习 http://www.uitestingplayground.com/progressbar当进度条达到 75% 时,我想按下一个按钮。 这是我的代码 Open Browser
我想用 Screen Should Contain 或 Screen Should Not Contain 替换 ${assertion_Keyword} 所以我想像关键字一样放置参数 check_e
如何循环遍历 Robot Framework 中的文件内容? 我的文件内容是这样的: 1001 1002 1003 1004 我想一一读取内容,将其分配给一个变量,然后对其进行一些操作。 最佳答案 R
我有一个 RF 测试,我需要打印变量值,而不是名称。 我正在尝试使用“ log to console Num: ${Num} ”,但 log.html 只显示: **KEYWORD** BuiltIn
如何将消息记录到 Robot 框架中的控制台,当我使用 log 关键字时,它会记录到报告文件中。请指教。 最佳答案 BuiltIn library 有一个名为 Log to console 的关键字这
假设我的源代码中有以下 HTML: ... some text ... 假设我通过以下方式找到了这个元素: ... ${web_element} Get Webelement id:myEleme
我无法在 Robot 框架中使用 sudo 命令,因为无法使用关键字“Run Process”输入密码。我们必须使用哪个关键字来做到这一点? PS:在我的项目中无法以 root 身份连接,因为此帐户已
从几天开始,我一直在尝试安装 robotframework RIDE,我尝试按照我在谷歌上搜索到的所有帖子进行操作,但仍然面临一些问题。以下是我遵循并得出的结论: 我已经成功安装了 python2.7
我们如何使用 Set Variable if带一个关键字,其中 Keyword 返回一个需要在 RobotFramework 中设置的变量. 例如:${Var} = set variable if $
我正在使用 python 使用 Robot Framework Selenium。我需要帮助来获取字符串的特定部分,而无需获取外部库。假设文字说“您的产品范围价格从 0 美元到 400 美元”,所以我
#我需要为通过案例生成随机测试字符串,对于失败案例我需要通过 excel 文件给出手动值 #我试过了: #Give input to new bill cycle [Arguments] ${C
我正在探索使用 Robot Framework 在 Python 中编写单元测试。我们目前有一些使用 pytest 开发的预先存在的单元测试。单元测试使用 mock.patch 方法模拟某些功能(例如
我用这个: ${today}= Get Time ${today_formated}= Convert Date ${today} result_format=%d 结果是 01,表示该月的第
例子: Log To Console This is the first argument This is the second argument This is the third ar
我有一条线: ${http_proxy}= Remove String %{HTTP_PROXY} http:// 在我的 test.txt for robot framework 无论环境变量
尝试验证元素是否包含特定文本,但关键字 Element Should Contain 找不到文本,即使我在 xpath 属性中明确输入它包含文本也是如此。但是关键字 Wait Until Page C
嗨,如果某个 bool 值为假,我想运行一个关键字,如果 Bool 为真,我这样做是为了运行一个关键字,但是如果 Bool 为假,我如何运行该关键字 Run Keyword If ${Bool}
在机器人框架测试用例中,我设置了一个变量,然后执行了一个过程。 因为变量的设置不是一个非常有趣的信息,我不想在我的报告中包含它。 | Verifying STUFF | | | ${endpoint
我无法在机器人框架中检查数据类型。我想评估变量的数据类型。 例如 ${variable} 123 现在我需要检查 ${variable}这里的值是否为整数。我尝试使用评估,但它提供了数据结构。
我是一名优秀的程序员,十分优秀!