Using variables
You can specify variables to refer to test objects or store simple values. After defining a variable to refer to a test object, you can use the variable instead of the entire object hierarchy in other statements. Using variables in this way makes your statements easier to read and to maintain.
Set statements
To specify a variable refer to an object, use the Set statement, with the following syntax:
Set ObjectVar = ObjectHierarchy
In the example below, the Set statement specifies the variable UserEditBox to store the full Browser.Page.WebEdit
object hierarchy for the username edit box. The Set method then enters the value tutorial
into the username edit box, using the UserEditBox variable:
Set UserEditBox = Browser("Advantage Shopping").Page("Advantage Shopping").WebEdit("username")
UserEditBox.Set "tutorial"
Simple values
Do not use the Set statement to specify a variable containing a simple value (such as a string or a number). The example below shows how to define a variable for a simple value.
MyVar = Browser("Advantage Shopping").Page("Advantage Shopping").WebElement("$2,690.97").GetTOProperty("innertext")
Dim statement
You can also use the Dim statement to declare variables of other types, including strings, integers, and arrays. This statement is not mandatory, but you can use it to improve the structure of your test or component. In the following example, the Dim statement is used to declare the passengers
variable, which can then be used in different statements within the current action.
Dim username
username = Browser("Advantage Shopping").Page("Advantage Shopping").WebEdit("username").GetTOProperty("value")