variable priorities in the robot framework

Variables from the command line

When executing tests, variables set in the command line take precedence over variables defined in Variable sections within test case files, as well as those imported from resource and variable files. This means that command line variables have the highest priority.

If you use the “–variable” option to set variables individually, they will override any variables set using the “–variablefile” option for variable files. Additionally, if the same variable is specified multiple times using the “–variable” option, the last one specified will override any earlier ones.

This feature enables you to set default variable values in a start-up script and then override them from the command line. However, it’s important to note that if multiple variable files contain the same variables, the ones in the file specified first will have the highest priority.

Variable section in a test case file

In a test case file, variables defined in the Variable section are accessible to all test cases within that file. These variables take precedence over any variables with the same name in any imported resource or variable files.

Furthermore, variables defined in the Variable section are available in all other sections of the file in which they are defined. This includes the Setting section, which can use these variables to import additional variables from resource and variable files.

Imported resource and variable files

In the hierarchy of variable priority in test data, variables imported from resource and variable files have the lowest priority. If multiple resource or variable files contain the same variables, the ones in the first imported file take precedence.

Resource files and variable files have the same priority when it comes to variable resolution. However, if a resource file imports other resource or variable files, variables defined within its own Variable section have higher priority than variables imported from other files. These variables are then available to any test files that import the resource file.

It’s important to note that variables imported from resource and variable files are not accessible within the Variable section of the file that imports them. This is because the Variable section is processed before the Setting section where the resource and variable files are imported.

Variables set during test execution

Variables that are set during test execution through the use of “Set Test/Suite/Global Variable” keywords or by returning values from other keywords always take precedence over any existing variables in their respective scope. This means that they effectively have the highest priority.

However, it’s important to note that these variables only affect the scope in which they are defined and do not impact variables outside of their scope. So while they may have the highest priority within their own scope, they do not have a global impact on other variables in the test data.

Built-in variables

Built-in variables, such as ${TEMPDIR} and ${TEST_NAME}, have the highest priority among all variables in test data. These variables cannot be overridden via the Variable section or command line, but they can be reset during test execution. It’s important to note that number variables are resolved dynamically if no variable is found, so they can be overridden, although it’s generally not recommended.

There is one exception to this rule: ${CURDIR} is a special variable that is replaced during the test data processing time, so it cannot be overridden or modified during test execution.

Leave a Comment

Your email address will not be published. Required fields are marked *

Ads Blocker Image Powered by Code Help Pro

Ads Blocker Detected!!!

We have detected that you are using extensions to block ads. Please support us by disabling these ads blocker.

Powered By
Best Wordpress Adblock Detecting Plugin | CHP Adblock