问题
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}
The error message I get is "List variable '@{versions}' has no item in index 0."
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!
回答1:
From a comment to the question you wrote:
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}
来源:https://stackoverflow.com/questions/38767791/how-to-feed-a-list-of-lists-as-an-argument-into-a-robot-framework-test-template