如何将列表列表作为参数提供给Robot Framework测试模板 [英] How to feed a list of lists as an argument into a Robot Framework Test Template
问题描述
我有做任何组合"测试的模板关键字,其中$ {labels}是一个列表,而$ {versions}是一个列表:
I have the template keyword for my "do any combination" test, where ${labels} is a list and ${versions} is a list of lists:
TT Process Instance Version Search
[Arguments] ${labels} ${versions}
Login
Process Instance Version Search ${labels} ${versions}
然后我创建一个测试套件文件并放置以下内容:
Then I create a test-suite file and place the following:
*** Settings ***
Test Template TT Process Instance Version Search
*** Variables ***
@{ProcessVersions} = ${Process0} ${Process1} ${Process2}
@{SingleVersion} = ${Process2}
@{Process0} = 1 2
@{Process1} = 3 test_version
@{Process2} = 1
@{SingleProcessLabel} = Label1
@{ProcessLabels} = Label1 Label2 Label3
*** Test Cases ***
Single Instance Version for a Single Process ${SingleProcessLabel} ${SingleVersion}
Distinct Instance Versions for Multiple Processes ${ProcessLabels} ${ProcessVersions}
我收到的错误消息是列表变量'@ {versions}'在索引0中没有任何项目."
我对此做了很多工作,包括使用嵌入参数,而我设法解决它的唯一方法是直接将$ versions作为全局变量提供.我的代码可以与全局变量一起很好地工作,但是我必须手动更改数据.我真正需要的是实现数据驱动的设计.
I played a lot with this, including using embedded arguments, and the only way I managed fixing it, is providing $versions directly as a global variable. My code works fine with global variables, but I have to change data manually. What I really need is implement data-driven design.
非常感谢您的任何建议和帮助!
Thanks a lot for any suggestions and help!
推荐答案
从评论到您写的问题:
问题是:如何将列表列表作为参数提供给Test模板?
The question is: How to feed list of lists as an argument into a Test template?
机器人框架用户指南中标题为列出变量.调用关键字时,如果在变量前面使用$
,则该变量将被视为列表对象.如果使用@
,则该变量将拆分为多个参数.
The answer to that is documented in the robot framework user guide, in the section titled List Variables. When calling a keyword, if you use a $
in front of the variable, the variable will be treated as a list object. If you use @
, the variable will be split into multiple arguments.
编写接受参数的关键字时,也是如此.如果只需要一个参数,则将$
用作参数变量.如果要将所有参数收集为列表,请使用@
.
When writing a keyword that accepts arguments, the same is true. If you want a single argument, use a $
for the argument variable. If you want to collect all arguments as a list, use @
.
这是一个显示几个示例的测试:
Here is a test that shows a couple of examples:
*** Variables ***
@{numbers} 1 2 3
@{letters} a b c d
@{listoflists} ${numbers} ${letters}
*** Keywords ***
Accept list of lists as single arg
[Arguments] ${arguments}
length should be ${arguments} 2
length should be ${arguments[0]} 3
length should be ${arguments[1]} 4
Accept multiple args
[Arguments] @{arguments}
length should be ${arguments} 2
length should be ${arguments[0]} 3
length should be ${arguments[1]} 4
*** Test cases ***
Pass list of lists as single argument
Accept list of lists as single arg ${listoflists}
Pass list of lists as multiple arguments
Accept multiple args @{listoflists}
Accept multiple args ${numbers} ${letters}
这篇关于如何将列表列表作为参数提供给Robot Framework测试模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!