RobotFramework: Global variables which change only locally

  • QA Engineer

    In the root of the test directory, I have this setting.robot file which includes the global variables used in all test suites and test cases. This file has been used as resource in all test cases:

    *** Variables ***
    ${Variable1}       value1
    ${Variable2}       value2
    ${Variable3}       value3
    ${Variable4}       value4

    Now suppose this is the test hierarchy I have:

    -- Suite1
    ------ Test1
    ------ Test2
    -- Suite2
    ------ Test3
    ------ Test4

    I might need to change the value of ${Variable1} in Test1, so in the setup of Test1 I use this code:

    Set Global Variable    ${Variable1}    NewValue

    The problem with this approach is the I am changing the value globally, and this will affect the other tests. Another solution is to use Set Variable:

    ${Variable1}=    Set Variable    NewValue

    The problem with this method is that this variable change does not affect the lower level user keywords:

    Prior to Robot Framework 2.9 variables in the local scope leaked to lower level user keywords. This was never an intended feature, and variables should be set or passed explicitly also with earlier versions.

    So how can I have global variables which can be changed per test case when needed without affecting other tests?

  • I don't have a Robot Framework environment to test right now but I think you can use:

    BuiltIn.Set test variable    ${variable1}    value

Log in to reply

Suggested Topics