QTP测试多个Windows应用程序的解决方案

来源:互联网 发布:新型网络传销模式 编辑:程序博客网 时间:2024/05/16 03:06

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

 

 

 

 

原创粉丝点击