0

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?

1

I don't have a Rf environment to test right now but i think you can use

BuiltIn.Set test variable    ${variable1}    value
1

You can use Set Test Variable as the previous answer mentioned.

This keyword :

Makes a variable available everywhere within the scope of the current test. Variables set with this keyword are available everywhere within the scope of the currently executed test case. For example, if you set a variable in a user keyword, it is available both in the test case level and also in all other user keywords used in the current test. Other test cases will not see variables set with this keyword.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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