Variables in Visual Tests

Testing applications usually involves using data. You can use data to test a part of an application, or use data throughout that application and other applications. You can type data into fields to test how the field accepts user input. You can also use data to determine how tests playback against a test application.

During recording, data input against a control is logged as literal data. For example, when a WPF TextBox control has a value typed into it, the resulting test step looks similar to the following: Enter "Ford".

This is acceptable, but the visual test can never use data other than the value Ford in that test step. However if the value Ford is replaced with a variable representing that data, whatever data is used in the variable is input in the TextBox control.

Using variables provides greater testing flexibility because data used in visual tests does not have to be constant.

Defining a variable for a visual test includes defining what kind of data it can hold. This characteristic of a variable is known as a data type. For visual tests, you can use variables of the following data types:

For example, when Silk Test Workbench records data input into controls, if the value recorded is in quotes (""), it is usually a Text data type and you can replace it with a variable of the Text data type.

Visual tests use the following types of variables:
  • Local – These are variables that are typically defined and used within a single visual test. Local variables can be used to store the values of other types of variables such as global or visual test variables. Choose Insert > Variable > Add Local to add a local variable, or define them in the Properties pane for the <<Start>> step.
  • Global – Global variables are defined within the context of a visual test, but can be used in any visual test that executes the visual test containing the global variable. When working with a visual test in the Visual Navigator, choose Insert > Variable > Set Global to define the value of a global variable. In other visual tests, choose Insert > Variable > Get Global to assign a global variable's value to a local variable.
  • Parameters – These are variables passed from one visual test to another visual test.
  • Input/Output Parameters – Use input parameters to pass data from a visual test to a script. Use output parameters to pass data from a script to a visual test.
  • Reserved – These are variables that are predefined. They can be used to retrieve information about visual test playback and other useful playback result information. Reserved variable names always begin with the ST prefix. Reserved variables are read-only, but can be used in expressions along with the other variable types.
Tip: Data can also be reused in scripts by using variables. For more information, see Variables in Scripts.