如何使用QTP腳本的封裝和調用方法

發表于:2009-06-17來源:作者:點擊數: 標簽:qtpQTP腳本封裝
把QTP腳本封裝起來,使其看起來一目了然! 簡單介紹一下方法: '啟動飛機訂票系統 Sub flight() SystemUtil.Run "D:\Program Files\ Mercury Interactive\ QuickTest Professional \samples\flight\app\flight4a.exe","","D:\Program Files\Mercury Interactiv
把QTP腳本封裝起來,使其看起來一目了然!

  簡單介紹一下方法:

  '啟動飛機訂票系統

  Sub flight()

  SystemUtil.Run "D:\Program Files\Mercury Interactive\QuickTest Professional\samples\flight\app\flight4a.exe","","D:\Program Files\Mercury Interactive\QuickTest Professional\samples\flight\app\","open"

  End Sub

  '登錄

  Sub login()

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

  Dialog("Login").WinEdit("Password:").SetSecure "48dda077c740a7e3a91bdb8caff1f6fae5f02d1b"

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

  End Sub

  '插入訂單

  Function insertorder()

  Window("Flight Reservation").ActiveX("MaskEdBox").Type "111111"

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

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

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

  Window("Flight Reservation").Dialog("Flights Table").WinList("From").Select "12538 LON 10:24 AM PAR 12:24 PM AF $162.40" 可以以數值代替如2

  Window("Flight Reservation").Dialog("Flights Table").WinButton("OK").Click

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

  Window("Flight Reservation").WinRadioButton("Business").Set

  Window("Flight Reservation").WinButton("Insert Order").Click

  Window("Flight Reservation").ActiveX("Threed Panel Control").WaitProperty "text", Insert Done..., 10000

  End Function

  '退出

  Sub logout()

  Window("Flight Reservation").Close

  End Sub

  其實就是把腳本按操作分段。然后以過程(SUB.....END SUB)或函數(FUNCTION ....END FUNCTION)進行封裝。

  這樣的腳本看上去一目了然,易理解也易于管理。

  QTP函數過程的調用

  以上面的QTP錄制腳本的封裝中的腳本為例:

  Call 過程名/函數名

  直接調用過程名/函數名

  也以飛機訂票系統為例。調用上面封裝的過程/函數:

  flight/call flight

  login/call login

  insertorder/Call insertorder

  logout/Call logout

  1. 調用SUB/FUNCTION方法是一樣的……除了CALL調用如果有參數則需要使用括號將參數變量括起來。

  2. SUB與FUNCTION的區別:SUB過程是沒有返回值的.但是FUNCTION是可以有返回值的。

原文轉自:http://www.anti-gravitydesign.com

国产97人人超碰caoprom_尤物国产在线一区手机播放_精品国产一区二区三_色天使久久综合给合久久97