How to Close All Browser from QTP Code

Most of the time I have seen that we need to close Internet Explorer while testing through QTP. Internet explorer means all the pop up , the main page. Say I am testing an application which need to navigate different URL. So what we generally do is to open a browser do what we want to do and close it for the next set of task may be in different URL.

A common testcase may be

1. Open IE and navigate to your HR link to create an employee.
2. After creation of the employee you need to close that and open another browser to register him to yahoo groups.
3. Now you need open some website called life insurance..fill up the data and employee number which is generated in Step-1.
4.Get the corresponding Policy number and again open HR link to update employee information.

For such cases to avoid the problem of multiple IEs we use to open a URL perform some task and close it after saving it.

Here is small code that will assist you to close an IE from QTP.

Sub CloseAllBrowsers()
End Sub
Now you can do further enhancement on this.
Say I have opened a meeting window and want to show my running window to our client or my seniors or there might be cases when I might open a test management tool like QC which runs on IE and want to run the test. So every time I will not be interested to open QC page.
This is a small modification on the code which will be helpful for such scenarios

On Error Resume Next
Dim intWndCnt
Dim oDesc, oWnd
'Create Object description
Set oDesc = Description.Create '
Set oWnd = Desktop.ChildObjects(oDesc)
intWndCnt = oWnd.Count
For i = 0 to intWndCnt - 1
Set TmpObj = oWnd.item(i)
strTmpTitle = oWnd.item(i).GetROProperty("Text")
If instr(1,strTmpTitle, "Microsoft Internet Explorer",1) > 0 Then
If instr(1,strTmpTitle, "Mercury Quality Center",1) > 0 Then
'msgbox "Title :" & oWnd.item(i).GetROProperty("Text")
'msgbox "Close :" & oWnd.item(i).GetROProperty("Text")
End if
End If
'Clean up
Set oDesc = nothing
Set oWnd = nothing
How to Close All Browser from QTP Code How to Close All Browser from QTP Code Reviewed by Animesh Chatterjee on December 21, 2008 Rating: 5

No comments:

Powered by Blogger.