我在机器人中的测试如下所示
${filter} = Create Filter with apps ${appList}
我已经在 yaml 文件中声明了变量 appList 并将其加载到我的测试文件中。 现在我的关键字文件如下
Create Filter with apps ${list}
${app_filter} = Generate app filters ${list}
生成应用程序过滤器是我的Python函数,如下
def generate_app_filters(appList=[]):
for app in appList:
print(app)
通过此设置,当我在变量 yaml 中将 ${appList} 值设置为 ["app1", "app2"] 时,它应该在 python 函数generate_app_filter 中被读取为 2 个单独的应用程序。我的预期输出应该如下所示
app1
app2
但是我的实际输出是这样的
[
"
a
p
p
1
"
,
"
a
p
p
2
"
]
我面临一个问题,generate_app_filters 以字符串形式接收参数。喜欢
"['app1', 'app2']"
,但不喜欢['app1', 'app2']
。因此,我的 Python 函数将每个字符读取为列表元素,但不是我想要的方式。
我的配置有问题吗?
您需要将变量作为列表参数传递,例如 @{} 和 not 作为 ${}
我稍微修改了你的Python定义(
test.py
):
def generate_app_filters(appList):
result_list = []
for app in appList:
result_list.append(app)
return result_list
这是机器人代码:
*** Test Cases ***
Verify that list is displayed
${filter} = Create Filter with apps ${my_App_list}
Log To Console First item of the list is ${filter}[0]
Log To Console Second item of the list is ${filter}[1]
*** Keywords ***
Create Filter with apps
[Arguments] ${LIST}
${myfilter} = test.Generate App Filters ${LIST} #'test' is the custom library definition
Return From Keyword ${myfilter}
此设置的输出是:
First item of the list is app1
Second item of the list is app2
希望这有帮助。