3

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?

1 Answer 1

7

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]}
Sign up to request clarification or add additional context in comments.

3 Comments

Now I feel kind of dumb. Went through Variable section several times, but didn't see that. Thank you very much!
Just fixed the link.
sneaky finnish lesson of the day :D

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.