2

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]}
4
  • Now I feel kind of dumb. Went through Variable section several times, but didn't see that. Thank you very much!
    – Itanium
    Jan 29, 2013 at 8:01
  • Just fixed the link.
    – jotrocken
    May 12, 2016 at 13:53
  • 1
    sneaky finnish lesson of the day :D
    – tuexss
    Jul 24, 2018 at 13:31
  • Thanks a lot.. :) Mar 21, 2019 at 10:57

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.