Method 1 -
'Check the existence of a browser and close it'until no more browsers existWhile Browser("creationtime:=0").Exist(0)'Close the browserBrowser("creationtime:=0").CloseWend
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 browserSet oBrowser = Description.CreateoBrowser("micclass").Value = "Browser"Set oPage = Description.CreateoPage("micclass").Value = "Page"'Get all browsersSet allBrowser = Desktop.ChildObjects(oBrowser)Dim i, iCountiCount = allBrowser.Count - 1For i = 0 To iCount'Get the page object from the browserSet oPg = allBrowser(i).ChildObjects(oPage)(0)'Get the URL of theIf InStr(oPg.GetROProperty("title"), "Quality Center", vbTextCompare) = 0 Then'Close the browserallBrowser(i).CloseEnd IfNext
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()

1805

被折叠的 条评论
为什么被折叠?



