QTP測試多個Windows應用程式的解決方案

TIB發表於2010-03-19

relevantcodes.com的《QTP: Working With Multiple Windows Applications》這篇文章介紹瞭如何測試多個相同Windows應用程式的方法:

http://relevantcodes.com/qtp-working-with-multiple-windows-applications/

 

其核心思想是把出現的視窗控制程式碼存到陣列中,並給視窗一個指定的名字,這樣後面訪問視窗物件時,只要指定名字就可以了。

 

核心類colWindows封裝在名為clsWindow.qfl的函式庫檔案中,主要由以下函式組成:

LaunchAdd: Launch a new window and retain its reference throughout the test cycle

AddNew: Automatically add a new open window to the collection without you having to specify its properties (see list of dependencies)

AddCustom: Adds a custom window by specifying its properties as an array

 

 

使用例子如下所示(其中WindowObject就是由colWindows類產生的物件):

'Please make sure the library file (clsWindow.qfl) is associated with the test.

'clsWindow.qfl is located in the test's directly: /clsWindow95Demo/clsWindow.qfl

'=================================

 

 

'============================================

'LaunchAdd

'============================================

 

'Open the AUT and add it to our collection as "Flight1"

'If using 9.2 and below:

WindowObject.LaunchAdd "C:/Program Files/HP/QuickTest Professional/samples/flight/app/flight4a.exe", "Flight1"

'If using 9.5 and higher:

'WindowObject.LaunchAdd "C:/Program Files/HP/QuickTest Professional/samples/flight/app/flight4a.exe", "Flight1"

'Use the reference we gave in the previous statement (Flight1):

With WindowObject.Name("Flight1")

       .WinEdit("attached text:=Agent Name:").Set "mercury"

       .WinEdit("attached text:=Password:").Set "mercury"

       .WinButton("text:=OK").Click

End With

 

 

'============================================

'AddCustom

'============================================

 

MsgBox "Demonstrating AddCustom: It will add the windows, whose properties we specify through an array."

 

'Add a custom window by specifying its description as FlightReservation2

WindowObject.AddCustom Array("regexpwndtitle:=Flight Reservation", "index:=1"), "FlightReservation2"

With WindowObject.Name("FlightReservation2")

       .Highlight

       .WinObject("attached text:=Date of Flight:", "index:=0").Type "09/09/12"

       .WinComboBox("attached text:=Fly From:", "index:=0").Select "Denver"

       .WinComboBox("attached text:=Fly To:", "index:=0").Select "Frankfurt"

       .WinButton("text:=FLIGHT").Click

End With

Dialog("micclass:=Dialog").WinButton("text:=OK").Click

With WindowObject.Name("FlightReservation2")

       .WinEdit("attached text:=Name:", "index:=0").Type "Relevant Codes 2"

       .WinButton("text:=&Insert Order").Click

       .WinObject("nativeclass:=AfxWnd40").WaitProperty "regexpwndtitle", "Insert Done...", 30000

End with

 

 

'============================================

'LaunchAdd

'============================================

 

'Open another instance of our AUT and add it to our collection as "Flight2"

'If using 9.2 and below:

WindowObject.LaunchAdd "C:/Program Files/HP/QuickTest Professional/samples/flight/app/flight4a.exe", "Flight2"

'If using 9.5 and higher:

'WindowObject.LaunchAdd "C:/Program Files/HP/QuickTest Professional/samples/flight/app/flight4a.exe", "Flight2"

'Use the reference we gave in the previous statement (Flight2):

With WindowObject.Name("Flight2")

       .WinEdit("attached text:=Agent Name:").Set "mercury"

       .WinEdit("attached text:=Password:").Set "mercury"

       .WInButton("text:=OK").Click

End With

 

 

'============================================

'AddNew

'============================================

 

MsgBox "Demonstrating AddNew: It will automatically add the newly open window and execute a few statements."

 

'Add the last open window to the collection as "FlightReservation1"

WindowObject.AddNew "FlightReservation1", 20

With WindowObject.Name("FlightReservation1")

       .Highlight

       .WinObject("attached text:=Date of Flight:", "index:=0").Type "09/09/12"

       .WinComboBox("attached text:=Fly From:", "index:=0").Select "Denver"

       .WinComboBox("attached text:=Fly To:", "index:=0").Select "Frankfurt"

       .WinButton("text:=FLIGHT").Click

End With

Dialog("text:=Flights Table").WinButton("text:=OK").Click

With WindowObject.Name("FlightReservation1")

       .WinEdit("attached text:=Name:", "index:=0").Type "Relevant Codes 1"

       .WinButton("text:=&Insert Order").Click

       .WinObject("nativeclass:=AfxWnd40").WaitProperty "regexpwndtitle", "Insert Done...", 30000

End with

 

 

 

'Release object

WindowObject.Destroy

 

 

 

 

相關文章