robotframework - 无法设置 RobotFramework 字典
问题描述
我写了这个简单的最小脚本来展示我是如何受苦的:
主机器人
Library Collections
Library BuiltIn
Library String
*** Variables ***
&{info} Create Dictionary
*** Test Cases ***
Case_00_Initialization
Log Hello 1 WARN
Set To Dictionary ${info} field1=A sample string
Log Hello 2 WARN
运行此代码
python -m robot -L TRACE --NoStatusRC main.robot
给我错误:
[ ERROR ] Error in file 'C:\test\main.robot' on line 7: Setting variable '&{info}' failed: Invalid dictionary variable item 'Create Dictionary'. Items must use 'name=value' syntax or be dictionary variables themselves.
==============================================================================
Main
==============================================================================
[ WARN ] Hello 1
Case_00_Initialization | FAIL |
No keyword with name 'Set To Dictionary' found.
------------------------------------------------------------------------------
Main | FAIL |
1 critical test, 0 passed, 1 failed
1 test total, 0 passed, 1 failed
==============================================================================
Output: C:\test\output.xml
Log: C:\test\log.html
Report: C:\test\report.html
应用程序应该info
在初始化时设置一个变量,它将在下一个测试用例中使用。但是我不想使用Set Global Variable
。
请注意,这是一个最小的工作示例,不建议field1
在Variables
部分设置。这不可能。连那个也解决不了问题No keyword with name 'Set To Dictionary' found
。
解决方案
在变量部分中,您不能使用关键字 - 这正是您在Create Dictionary
那里所做的。
您可以向其中添加一些键:值(例如 "field" ,但您不允许我们这样做;),或者 - 您可以将其初始化为空字典(例如{}
在 python 中)。后者是通过传递特殊值来完成的&{Empty}
:
*** Variables ***
&{info} &{Empty}
推荐阅读
- java - wildfly / jboss-eap:如何命名 JMS 资源以匹配 EJB2 ejb-jar.xml
- sql-server - 如何将数据库永久设置为 SINGLE_USER 模式?
- excel - 使用 excel office 脚本将多个表中的特定列合并到一个表中
- python - 为什么当我在 shell 中正常运行但通过 Python 的 Popen 失败时,这个 bash 命令会起作用?
- javascript - 使用画布为图像元素拍照
- javascript - 服务器和前端的电子构建问题
- ios - iOS 15:删除 UITableView 中单元格前的空白
- mysql - JSON初学者:(我可以/我如何/应该)以特定方式将干净的JSON数组自动转换为许多SQL表?
- memory - INSERT 命令失败,在 bigquery 中出现“无法在内存限制内解析数据”
- ios - iOS - Swift - 来自 plist 的地理围栏通知