33.5 Levels for Variable Definitions

Note This section answers the question of at which level a variable should be defined. If you are currently not interested, you can skip directly to the next chapter.

Variables can be bound at different levels:

The level at which a variable is best defined depends on the purpose of the variable:

Procedure parameters
Pass a value as a parameter to a procedure if the same procedure is to be executed more than once with different values. Procedure parameters are specified in the Variable definitions table of a Procedure call node.
Local variables in a procedure
Local variables are defined within the procedure and are valid only there. When the procedure finishes, they are deleted. Use a local variable if it is not needed outside the procedure. They are the tool of choice for intermediate results.
Local variables in a test case
In a test case, local variables can either be created during the execution of the test case or via the corresponding table in the details of the Test case node. If you use the same value multiple times within a test case, it makes sense to assign it to a variable once and then use the variable. This improves maintainability. Local variables should also be used for intermediate results.
Global variables
When global variables have been created, they exist until they are explicitly deleted or until QF-Test is closed. They even survive stops and re-execution of tests. Use them for values that are needed in multiple test cases. An example is the variable client which is created in the Setup node when starting the application. To get rid of them, choose the menu »Playback«-»Clear global variables«. They are also cleared when QF-Test terminates.
Command line parameters
Variables set via the command line are useful in batch mode when you want to perform multiple batch runs with different values. Command line parameters apply for the entire duration of the batch run. A typical example is variable-driven execution across different browsers. Variables can be specified via the command line parameter -variable (cf. chapter 'Command line arguments' in the manual).
Test suite variables
Test suite variables can be used by all test cases. Their purpose corresponds to that of global variables, except that in batch mode they can be overridden by variables on the command line.
Default values (secondary stack)
You can define default values for the variables of procedures, test cases and test case sets. These apply if no variable with the same name has been defined at a higher level.