QTP测试多个浏览器窗口的解决方案

 

relevantcodes.com的《QTP: Working with Multiple Browser Applications》这篇文章介绍了如何测试多个浏览器窗口的情况:

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

 

解决办法的关键是根据什么来区别出不同的浏览器窗口并保存其句柄。文章介绍了2类方法:

1、使用标题来识别出浏览器窗口并保存浏览器窗口句柄

2、最近打开的浏览器窗口拥有的CreationTime属性最大,可以据此来区别不同的浏览器窗口,并分别保存它们的句柄

 

把这些识别并保存浏览器窗口句柄的代码封装在clsBrowser.cls文件中的colBrowser类。主要函数有:

AddUsingTitleUses the "AddBrowser" method to add browsers to the collection using their Title Property

AddUsingCreationTime Uses the "AddBrowser" method to add browsers to the collection using their CreationTime Property

AddLastOpenUses the "AddBrowser" method to add the last (most recent) open browser

Note: The last open browser always has the greatest CreationTime

 

 

使用例子如下所示(BrowserObject对象就是colBrowser类产生的对象):

 

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

' Add Using Title

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

SystemUtil.Run "iexplore.exe", "http://newtours.demoaut.com", "", "", 3 : Wait(4)

'Add the browser above using its title, and with the name DemoAUT

BrowserObject.AddUsingTitle "DemoAUT", ".*Mercury Tours.*"

 

SystemUtil.Run "iexplore.exe", "http://blog.csdn.net/testing_is_believing", "", "", 3 : Wait(4)

'Add the browser above using its title, and with the name RelevantCodes

BrowserObject.AddUsingTitle "MyBlog", "实用性测试(Pragmatistic Testing - CSDN博客"

 

With BrowserObject.Name("DemoAUT")

       .WebEdit("name:=userName").Set "test"

       .WebEdit("name:=password").Set "test"

       .Image("name:=login").Click

 

       .Sync

      

       If .WebList("name:=fromPort").Exist(10) Then

              .WebList("name:=fromPort").Select "Frankfurt"

              .WebList("name:=fromMonth").Select "December"

              .WebList("name:=toPort").Select "Paris"

              .WebList("name:=toMonth").Select "December"

              .WebRadioGroup("name:=servClass").Select "#1"

              .WebList("name:=airline").Select "Unified Airlines"

              .Image("name:=findFlights").Click

       End If

End with

 

With BrowserObject.Name("MyBlog")

       .Link("text:=QTP自动化测试实践》", "index:=").Click

End with

 

With BrowserObject

       .Name("DemoAUT").Close

       .Name("MyBlog").Close

End with

 

 

 

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

' Add Last Open

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

SystemUtil.Run "iexplore.exe", "http://newtours.demoaut.com", "", "", 3 : Wait(4)

'Add the above browser using AddLastOpen

BrowserObject.AddLastOpen "DemoAUT"

 

SystemUtil.Run "iexplore.exe", "http://blog.csdn.net/testing_is_believing", "", "", 3 : Wait(4)

'Add the above browser using AddLastOpen

BrowserObject.AddLastOpen "MyBlog"

 

With BrowserObject.Name("DemoAUT")

       .WebEdit("name:=userName").Set "test"

       .WebEdit("name:=password").Set "test"

       .Image("name:=login").Click

 

       .Sync

      

       If .WebList("name:=fromPort").Exist(10) Then

              .WebList("name:=fromPort").Select "Frankfurt"

              .WebList("name:=fromMonth").Select "December"

              .WebList("name:=toPort").Select "Paris"

              .WebList("name:=toMonth").Select "December"

              .WebRadioGroup("name:=servClass").Select "#1"

              .WebList("name:=airline").Select "Unified Airlines"

              .Image("name:=findFlights").Click

       End If

End with

 

With BrowserObject.Name("MyBlog")

       .Link("text:=QTP自动化测试实践》", "index:=").Click

End with

 

With BrowserObject

       .Name("DemoAUT").Close

       .Name("MyBlog").Close

End with

 

 

 

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

' Add Using CreationTime

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

SystemUtil.Run "iexplore.exe", "http://newtours.demoaut.com", "", "", 3 : Wait(4)

'Add the above browser using CreationTime 0, assuming no other browsers are open

BrowserObject.AddUsingCreationTime "DemoAUT", 0

 

SystemUtil.Run "iexplore.exe", "http://blog.csdn.net/testing_is_believing", "", "", 3 : Wait(4)

'Add the above browser using CreationTime 1, assuming no other browsers are open prior to above

BrowserObject.AddUsingCreationTime "MyBlog", 1

 

With BrowserObject.Name("DemoAUT")

       .WebEdit("name:=userName").Set "test"

       .WebEdit("name:=password").Set "test"

       .Image("name:=login").Click

 

       .Sync

      

       If .WebList("name:=fromPort").Exist(10) Then

              .WebList("name:=fromPort").Select "Frankfurt"

              .WebList("name:=fromMonth").Select "December"

              .WebList("name:=toPort").Select "Paris"

              .WebList("name:=toMonth").Select "December"

              .WebRadioGroup("name:=servClass").Select "#1"

              .WebList("name:=airline").Select "Unified Airlines"

              .Image("name:=findFlights").Click

       End If

End with

 

'Added Index - November 06, 2009 - Credits: Clive Farrington

With BrowserObject.Name("MyBlog")

       .Link("text:=QTP自动化测试实践》", "index:=").Click

End with

 

With BrowserObject

       .Name("DemoAUT").Close

       .Name("MyBlog").Close

End with

 

 

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值