Tuesday, 7 February 2012

How to handle Multiple Browsers in QTP

At times we need to handle or work with Multiple Browsers when executing the test scripts. QTP provides a mechanism to handle this kind of situation.We can use the ordinal identifiers "INDEX" and "CreationTime" to differentiate the browsers at runtime.

I am going to explain the above mentioned scenario with some examples.

Example: 01
SystemUtil.exe "iexplorer.exe" // Line 1
Browser("micClass:Browser"). Navigate "http://aa.com // Line 2

The above code snippet will launch a new browser and open the site mentioned in line 2.

Launch second browser.
SystemUtil.exe "iexplorer.exe" // Line 3
SystemUtil.exe "iexplorer.exe" // Line 4 Launch a dummy browser
Wait 15  // Waiting for the browsers to load properly

Now try to navigate to some site.This time we can't use the string "micClass:Browser" as there are 2 browsers are opened. In this case we need to go for the ordinal identifier "CreationTime" as I previously mentioned.Use the following code snippet to open a site with CreationTime identifier.

Browser("CreationTime:=0").Navigate "http://aa.com"  // Line 5

We'll get the error "multiple objects found" once the Line 5 is executed.Because "micClass:=Browser" is common for both the browsers.

To eliminate this error we can use the ordinal identifier "index" or "CreationTime" as follows to differentiate the browsers.

To represent the 1st Browser we can use the following code snippet.
Browser("micClass:=Browser","index:=0").Navigate "http://aa.com"
Browser("micClass:=Browser","creationtime:=0").Navigate "http://aa.com"
Browser("index:=0").Navigate "http://aa.com"
Browser("creationtime:=0").Navigate "http://aa.com"

To represent the 2nd Browser we can use the following code snippet.
Browser("micClass:=Browser","index:=1").Navigate "http://aa.com"
Browser("micClass:=Browser","creationtime:=1").Navigate "http://aa.com"
Browser("index:=1").Navigate "http://aa.com"
Browser("creationtime:=1").Navigate "http://aa.com"


Post a Comment

Back To Top