QTP的Action間的資訊共享的4種方法

2021-08-22 16:55:14 字數 4096 閱讀 8320

通過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")

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前清空裡面的資料

ifglobaldictionary.count > 0then

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

QTP的Action間的資訊共享的4種方法

分享一下我老師大神的人工智慧教程!零基礎,通俗易懂!通過action引數來傳遞資料 action2的指令碼如下 input parameters message parameter msg msgbox message output parameters if not message then pa...

QTP中Action的引數呼叫

一 action的引數呼叫1 1 設定引數 action properters action parameter 增加input的引數和output的引數 2 action 1 的指令碼 parameter output action1 output msgbox action1 input met...

該使用QTP的Action還是Function?

will roden在 actions vs functions in qtp 9.0 一文章歸納了qtp在action和function的使用上的一些區別 1 處理資料 actions只能接受有限的資料型別作為引數 string integer等 function可以接受array diction...