Search code examples
robotframework

How to set dependent global variables in robot framework


I have a resources file containing a global variable which is dependent on another global variable.

${VAR1}    ${EMPTY}
${VAR2}    some_value/${VAR1}.json

In my testcase I set the value for ${VAR1} using the set global variable keyword

set global variable  ${VAR1}  foo
log  ${VAR1}
log  ${VAR2}

I am expecting that the update to ${VAR1} in turn updates ${VAR2} as well so the output should be:

foo
some_value/foo.json

and not

foo
some_value/${EMPTY}.json

Solution

  • ${Var2} is passed from command line , which has the highest priority. In order to override it , you need to define ${var2} in your Keyword file again, as you did for ${var1}

    Example

    set Suite variable  ${VAR1}  foo
    set Suite variable  ${VAR2}  some_value/${VAR1}.json
    

    You can also refer this answer

    Command Line Varaible is not overriding Suite Level Variable in Robot Framework