Reputation: 83
I'm having a problem reading a list variable from a file. I have a file (variables.py) with 3 variables :
TEST1=212
TEST2=[111, 222, 333, 444, 555, 666]
TESTS3="sadasd"
Both ${TEST1}
and ${TEST3}
are accessible (I get values from variable file)
But when I try to access second variable with @{TEST2}[2]
, I get an error :
FAIL : Non-existing variable '@{TEST2}[2]'
This only happens, if I try to use variables from file. If I create list variable in RIDE, I can easly access it with @{Variable}[{$index}]
If I try this syntax : ${TEST2}[2]
, I get :
'[111, 222, 333, 444, 555, 666][2]'
So robotframework knows that there is a variable with given name, but doesn't know that it's a list variable. Am I doing something wrong?
Upvotes: 3
Views: 53258
Reputation: 1017
To distinguish explicitly between a list that is a value of a scalar variable and a list variable, you have to use LIST__
prefix for @{vars} in the variable file. See Robot Framework User Guide: Creating variables directly for details.
In your case, this would be:
LIST__TEST2 = [111, 222, 333, 444, 555, 666]
In general, there are three ways to initialize lists in variable files:
STRINGS = ["one", "two", "three", "four"]
LIST__STRINGS = ["one", "two", "three", "four"]
Do not confuse this with the syntax for the *** Variables ***
section, where initializing a list would be:
*** Variables ***
@{STRINGS} | one | two | three | four
You can access individual elements in a list assigned to scalar variable like this:
${TEST2[0]}
Upvotes: 7