How to close all browsers other than ALM in UFT using Descriptive Programming. – User friendly Tech help
Requirement:– Close all browsers other than Application life cycle (ALM/QC)
n
n
Kill browser other than ALM |
n
Solution:– We followed the concept of Descriptive Programming in UFT to achieve the result.
n
nApproach:– Very simple and straight flow,look for all the opened browsers (Creating DP object ). Incase browser is not ALM close it.
n
nHow to Kill Process from Task Manager
n
Code:-
n
'*******************************************Function************************************************
n
'Function Name:- fn_CloseBrowser
'Function Description:- Function to close browser other than ALM instance using DP approach
'Input Parameters:- None
'Output Parameters:- None
''**************************************************************************************************
'function call fn_CloseBrowser
Sub fn_CloseBrowser ()
Dim iCnt :iCnt = 0
'Incase Occur occurs move to next step
On Error Resume Next
'Using Descriptive Programming in UFT to create the browser object
Set objBrowser = Description.Create
objBrowser("micclass").Value = "Browser"
'Creating the Page Desription
Set objPage = Description.Create
objPage("micclass").Value = "Page"
'Get all browsers which are opened
Set allBrowser = Desktop.ChildObjects(objBrowser)
'Taking the count of browsers
iCntBrowser = allBrowser.Count - 1
'if no browsers were found, exit
If iCntBrowser < 0 Then
Msgbox "No opened Browser found!!!"
Exit Sub
End If
'Looping untiL the last opened browser
For iCnt = 0 To iCntBrowser
'Get the page object from the browser
Set objPg = allBrowser(iCnt).ChildObjects(objPage)(0)
'exit if the last open browser is ALM (as we don't want to close this)
If iCntBrowser=0 AND InStr(objPg.GetROProperty("title"), "HP Application Lifecycle Management") > 0 Then
On Error GoTo 0
Msgbox "Only ALM browser is opened!!!"
Exit Sub
End If
'Close the browser
If InStr(objPg.GetROProperty("title"), "HP Application Lifecycle Management") = 0 Then allBrowser(iCnt).Close
End If
Next
'Destroying the objects
Set objBrowser = Nothing
Set objPg = Nothing
Set objPage = Nothing
End Sub