Import Variables in Suite Setup does not import variables for all the test suite

18 views Asked by At

I am kinda new with Robot. similarly to this How to make variables from 'Import Variables' globally available?

I am trying to import dynamically variables defined in a python file depending if the tester specified --variable device:A or device:B

Both devices have the same variables but values are different.

My repo looks like this:

folder
      |_ __init__.robot
      |_ test.robot

I have something like that in the __init__.robot:

In __init__.robot:

Suite Setup      Initialize Device

*** Keywords ***    
Initialize Device
    [Documentation]    Initializes the device based on a constant value
    [Arguments]    ${device_type}
    IF   '${device_type}' == 'A'
        Import Variables  projects/A/variables_A.py
    ELSE IF    '${device_type}' == 'B'
        Import Variables  projects/B/variables_B.py
END

And in test.robot:

*** Test Cases ***
Print device ID
    Log ${device_id}

The variable device_id is defined in both variables_X.py files

It works fine for the Setup Suite function, variables are loaded as I expected but as soon as my first test starts, the variables imported are unknown, like out of scope. I thought importing them from the Suite Setup would import them for the whole Test suite as described by robot manual:

Variables imported with this keyword are set into the test suite scope similarly when importing them in the Setting table using the Variables setting.

My solution would be to iterate this file and use Set Global Variable/Set Suite Variable but I am curious to know why it does not work as I expected, any ideas?

0

There are 0 answers