How to close all browsers other than ALM in UFT using Descriptive Programming.

Requirement:– Close all browsers other than Application life cycle (ALM/QC) 

Kill browser other than ALM 


Solution:– We followed the concept of Descriptive Programming in UFT to achieve the result.

Approach:– Very simple and straight flow,look for all the opened browsers (Creating DP object ). Incase browser is not ALM close it.

How to Kill Process from Task Manager 

Code:-


'*******************************************Function************************************************
'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
ufthelp

One thought on “How to close all browsers other than ALM in UFT using Descriptive Programming.”

  1. Public Sub CloseAllBrowsersExceptALM ()
    Dim vcol_Handles, vCtr, vHwnd, Flag, vLastHWnd,sCompare,sALMCompareString
    vCtr = 0
    Flag = true

    Set vcol_Handles = CreateObject("Scripting.Dictionary")
    While (Window("regexpwndclass:=IEFrame","index:=" & vCtr).Exist(0) And Flag)
    wait 1
    vHwnd = Window("regexpwndclass:=IEFrame","index:=" & vCtr).getroproperty("Hwnd")
    If (vLastHWnd=vHwnd) Then
    Flag = false
    Else
    vcol_Handles.Add CStr(vcol_Handles.Count),vHwnd
    vCtr = vCtr+1
    End If
    vLastHWnd = vHwnd
    Wend

    For vCtr = vcol_Handles.Count-1 to 0 step -1
    vHwnd = vcol_Handles.Item(CStr(vCtr))
    sALMCompareString = "HP Application Lifecycle Management"
    sCompare=Instr(Window("hwnd:=" &vHwnd).getroproperty("title"),sALMCompareString)
    If (sCompare=0) or (IsNull(sCompare)) then
    Window("hwnd:=" &vHwnd).Close
    If Dialog("nativeclass:=#32770").WinButton("text:=Close all &tabs").Exist(1) then
    Dialog("nativeclass:=#32770").WinButton("text:=Close all &tabs").Click
    End If
    End If
    Next
    End Sub

Leave a Reply

Your email address will not be published. Required fields are marked *