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()