Comments (image map) Parameters (image map) Parenthesis (image map) Calculations (image map) Variables (image map)

变量

相关项: GUI 操作、脚本化 GUI 组件和函数库

可以指定变量以存储操作、脚本化组件或函数库中的测试对象或简单值。将变量用于测试对象时,可以在其他语句中使用该变量而无需使用整个对象层次结构。以此方式使用变量可使语句更易于阅读和维护。

要指定变量来存储对象,请按照以下语法使用 Set 语句:

Set 对象变量 = 对象层次结构

在下面的示例中,Set 语句指定变量 UserEditBox 来存储 username 编辑框的完整 Browser.Page.WebEdit 对象层次结构。然后,Set 方法会使用 UserEditBox 变量将值 tutorial 输入到 username 编辑框中:

Set UserEditBox = Browser("Advantage Shopping").Page("Advantage Shopping").WebEdit("username")
UserEditBox.Set "tutorial"

备注: 不要使用 Set 语句指定包含简单值(比如字符串或数字)的变量。下面的示例显示了如何定义简单值的变量:

MyVar = Browser("Advantage Shopping").Page("Advantage Shopping").WebEdit("username").GetTOProperty("type")

还可以使用 Dim 语句声明其他类型的变量,包括字符串、整数和数组。此语句不是必需语句,但可以用它改进操作、脚本化组件或函数库的结构。

示例: 下面的示例演示使用 Dim 语句声明变量:

在操作或脚本化组件中 (使用 TrackingNumber 变量):

Dim TrackingNumber
TrackingNumber = Browser("Advantage Shopping").Page("Advantage Shopping").WebElement("trackingNumberLabel").GetTOProperty("innertext")

在函数库中(使用 actual_value 变量):

Dim actual_value
	' Get the actual property value
	actual_value = obj.GetROProperty(PropertyName)