Variables in VBScript
You can specify variables to store test objects or simple
values in your test or function library. When using a variable for 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.
To specify a variable to store 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 John into the username
edit box, using the UserEditBox variable:
Set UserEditBox = Browser("Mercury Tours").Page("Mercury
Tours").WebEdit("username")
UserEditBox.Set "John"
Note: 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("Mercury Tours").Page("Mercury Tours").WebEdit("username").GetTOProperty("type")
MyVar = Browser("Mercury Tours").Page("Mercury Tours").WebEdit("username").GetTOProperty("type")
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 function library. 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 or function library:
Dim passengers
passengers = Browser("Mercury Tours").Page("Find
Flights").WebEdit("numpassengers").GetROProperty("value")
No comments:
Post a Comment