QTP的Action間的信息共享的4種方法 軟件測試
通過Action參數來傳遞數據
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 = DataTable.GetSheet("Global")
' 查找參數列
Set Parameter1 = Sheet.GetParameter("Column1")
Set Parameter2 = Sheet.GetParameter("Column2")
' 設置參數值
Parameter1.Value="Hello"
Parameter2.Value="World!"
' 調用Action2,Action2將使用前面設置的參數值
RunAction "Action2", oneIteration
在Action2中讀取參數值,Action2的腳本如下:
' 獲取全局數據表
Set Sheet = DataTable.GetSheet("Global")
' 讀取參數值
Set Parameter1 = Sheet.GetParameter("Column1")
Set Parameter2 = Sheet.GetParameter("Column2")
' 使用參數值
Msgbox Parameter1 &" " & Parameter2
使用環境變量(Environment Variables)來共享數據
在Action1中使用環境變量中定義的LoginUserName和LoginPassWord,Action1的腳本如下:
' 在Action1中使用環境變量中定義的LoginUserName和LoginPassWord
UserName = Environment.Value("LoginUserName")
UserPassWord = Environment.Value("LoginPassWord")
SystemUtil.Run "C:\Program Files\Mercury Interactive\QuickTest Professional\samples\flight\app\flight4a.exe"
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 = Environment.Value("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_USER\Software\Mercury Interactive\QuickTest Professional\MicTest\ReservedObjects\GlobalDictionary
ProgID = "Scripting.Dictionary"
(2)使用GlobalDictionary對象
' 使用GlobalDictionary前清空里面的數據
If GlobalDictionary.Count > 0 Then
GlobalDictionary.RemoveAll
End If
' 存儲一個數值
DepartDate = "2008-3-31"
GlobalDictionary.Add "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
原文轉自:http://www.anti-gravitydesign.com