Header Ads

How to Count Number of open Browsers in Desktop Using QTP

This is a very common problem for fewly joined automation test engineers to find out the number of open browsers in desktop using QTP.

For this the concepts we will be using are:
1. ChildObject
2. Descriptive programming

with ChildObejct we will see how many objects are present under desktop as a child.
And with description we will determine if the child matches with our description

This is the function that returns the no of browser count

Function count_Browser()

Dim objDesc ‘As Description
Dim objBrowsers ‘As Collection
Set objDesc = Description.Create
objDesc(“micclass”).Value = “Browser”
Set objBrowsers = Desktop.ChildObjects(objDesc)
for l_BrowserIndex = 0 to objBrowsers.Count - 1
count_Browser=objBrowsers.Count 'returns no of browser
strTemp = (l_BrowserIndex).GetROProperty("hwnd")
strTemp = (l_BrowserIndex).GetROProperty("title")
Set objBrowser = Nothing
count_Browser=strTemp 'returns the title
Set objBrowsers = Nothing
Set objDesc = Nothing
End function

When we use this function:
1. When we need to understand how many browsers present.
2. If we have do certain operation with any of the browser. Like- let the first browser be open but second needs to be closed.
Powered by Blogger.