Pass variables from one test case to another in Robot framework (Global variable)

user5260816 picture user5260816 · Jan 19, 2016 · Viewed 22.7k times · Source

I have one test suit with two test cases. I have one same-name variable between the two test cases, let's say ${X}. The first test case changes the value of this variable. The second test case, gives me the following error Variable '${X}' not found.

How can I have something like a Global Variable? Like if it is defined in one test case, the next test case will recognize this variable and use the new value and so on

Answer

Radhakrishna Pemmasani picture Radhakrishna Pemmasani · Jan 20, 2016

Try this,when ever you are trying to change the value of variable then make that variable Global, this meets your requirement so when the variables are logged in the below example it has the latest value stored in the variable.

    *** Test Cases ***
Test1
    ${test}=    Evaluate    9
    Set Global Variable      ${test} 
Test2
    ${test}=    Evaluate    10
    Set Global Variable      ${test} 
Test
    Log Variables