How to Close All Open Browsers Using QTP

Ways to close all open browsers:

Method 1 -

'Check the existence of a browser and close it 'until no more browsers exist  While Browser("creationtime:=0").Exist(0)      'Close the browser     Browser("creationtime:=0").Close  Wend

Limitation – The code does not allow to ignore any specific browser (like Quality Center)
Though there another way by which can enumerate all open browser and close them in QTP and below demonstrates the same

Method 2 -

'Create a description for browser  Set oBrowser = Description.Create oBrowser("micclass").Value = "Browser"  Set oPage = Description.Create oPage("micclass").Value = "Page"  'Get all browsers Set allBrowser = Desktop.ChildObjects(oBrowser)  Dim i, iCount  iCount = allBrowser.Count - 1  For i = 0 To iCount     'Get the page object from the browser     Set oPg = allBrowser(i).ChildObjects(oPage)(0)      'Get the URL of the        If InStr(oPg.GetROProperty("title"), "Quality Center", vbTextCompare) = 0 Then               'Close the browser                allBrowser(i).Close       End If Next

Method 3 -

SystemUtil.CloseProcessByName("IExplore.exe")

Method 4 -

SystemUtil.CloseProcessByWndTitle "Title" ,False(Enable Regexp)

Method 5 -

SystemUtil.CloseDescendentProcesses CloseDescendentProcesses can be used to close any process launched by QTP. The code below illustrates the usage 'Launch explorer SystemUtil.Run "iexplore.exe" 'Launch excel using COM Set oXL = CreateObject("Excel.Application") oXL.Visible = True 'Close processes launched by QTP. This will close 'the internet explorer and Excel as well SystemUtil.CloseDescendentProcesses ****This method is best suited to be used during the end of a script to cleanup any process left open.

Method 6 -

‘Close All Browsers Except QC

Public function closebrowsers()

Do while("True") check = Browser("opnedbytestingtool:=True").Exist if(check = "False") then exit do else Browser("opnedbytestingtool:=True").close end if loop

End function

closebrowsers()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值