2024年4月27日发(作者:)

Action2的脚本如下:

' Input Parameters

Message = Parameter("Msg")

Msgbox Message

' Output Parameters

If NOT Message = "" Then

Parameter("ReturnMsg") = "The Message is " & Message

Else

Parameter("ReturnMsg") = "The Message is Empty!"

End If

' RetuenValue

ExitAction "HAHAHAHHAHA!!!!!"

'ExitAction Parameter("ReturnMsg")

3种调用Action的方法,Action1的脚本如下:

' 调用Action2,输入参数为 “ Hello!”,把输出参数值写到ReturnMessage1变

RunAction "Action2", oneIteration,"Hello!" ,ReturnMessage1

Msgbox ReturnMessage1

' 调用Action2,输入参数为 “ Hello!”,通过Parameter方法读取输出参数值

RunAction "Action2", oneIteration,"Hello!"

ReturnMessage2= Parameter("Action2","ReturnMsg")

Msgbox ReturnMessage2

' 如果被调用的Action使用了ExitAction来退出Action并返回ReturnValue,

则可以使用下面的方式来获取Return Value的值

' 注意OutPut Parameters与Return Value的区别

ReturnMessage3 = RunAction( "Action2", oneIteration ,"Hello!")

Msgbox ReturnMessage3

通过全局数据表(Global Data Table)来共享数

在Action1中设置参数值,Action1的脚本如下:

' 获取全局数据表

Set Sheet = et("Global")

' 查找参数列

Set Parameter1 = ameter("Column1")

Set Parameter2 = ameter("Column2")

' 设置参数值

="Hello"

="World!"

' 调用Action2,Action2将使用前面设置的参数值

RunAction "Action2", oneIteration

在Action2中读取参数值,Action2的脚本如下:

' 获取全局数据表

Set Sheet = et("Global")

' 读取参数值

Set Parameter1 = ameter("Column1")

Set Parameter2 = ameter("Column2")

' 使用参数值

Msgbox Parameter1 &" " & Parameter2

使用环境变量(Environment Variables)来共

享数据

在Action1中使用环境变量中定义的LoginUserName和LoginPassWord,

Action1的脚本如下:

' 在Action1中使用环境变量中定义的LoginUserName和LoginPassWord

UserName = ("LoginUserName")

UserPassWord = ("LoginPassWord")

"C:Program FilesMercury InteractiveQuickTest

"

Dialog("Login").Activate

Dialog("Login").WinEdit("Agent Name:").Set UserName

Dialog("Login").WinEdit("Password:").SetSecure UserPassWord

Dialog("Login").WinButton("OK").Click

' 调用Action2,在Action2中也将使用到定义的环境变量

RunAction "Action2", oneIteration

在Action2中使用环境变量中定义的LoginUserName,Action2的脚本如下:

' 在Action2中使用环境变量中定义的LoginUserName

UserName = ("LoginUserName")

Window("Flight Reservation").Activate

Window("Flight Reservation").WinObject("Date of Flight:").Click 1,6

Window("Flight Reservation").WinObject("Date of Flight:").Type

"121212"

Window("Flight Reservation").WinComboBox("Fly From:").Select

"Denver"

Window("Flight Reservation").WinComboBox("Fly To:").Select

"Frankfurt"

Window("Flight Reservation").WinButton("FLIGHT").Click

Window("Flight Reservation").Dialog("Flights

Table").WinList("From").Select "14243 DEN 12:57 PM FRA 01:41

PM SR $110.00"

Window("Flight Reservation").Dialog("Flights

Table").WinButton("OK").Click

Window("Flight Reservation").WinEdit("Name:").Set UserName

通过Dictionary对象来在Action之间共享数据

(1)添加注册表

HKEY_CURRENT_USERSoftwareMercury InteractiveQuickTest

ProfessionalMicTestReservedObjectsGlobalDictionary

ProgID = "nary"

(2)使用GlobalDictionary对象

' 使用GlobalDictionary前清空里面的数据

If > 0 Then

All

End If

' 存储一个数值

DepartDate = "2008-3-31"

"DateCheck", DepartDate

' 可在当前Action使用GlobalDictionary中的数据,也可在另外一个Action中

使用添加到GlobalDictionary的数据

'Dim CompareDate

'CompareDate=GlobalDictionary("DateCheck")

'Msgbox CompareDate

' 可在当前Action使用GlobalDictionary中的数据,也可在另外一个Action中

使用添加到GlobalDictionary的数据

Dim CompareDate

' 读取GlobalDictionary中的DateCheck数据

CompareDate=GlobalDictionary("DateCheck")

Msgbox CompareDate