Thursday, June 3, 2010

QTP-IE-Close All Browsers

One thumb role in testing in general and Automation in specific is get the application to the base state after completion of testing or before starting the test.

With QTP used against web application, there are chances the script fail due to object recognition issues when multiple browser instances are open.
The risk of failure however can be mitigated by using unique properties for each object, but mostly it is advised to close all open instances of browsers if not required for test execution.

Multiple ways of doing it :
Use of IE DOM to close the instances
Use of VBscript to kill all open IE processes
Use of native QTP code to check the window properties and close the browsers

One instance is noted below


'Close all open browser opened before QTP launch
'Skip TD/QC if already open
'vTDString : To Skip open TD/QC browsers, pass the window name as parameter

Do while Window("title:=.*Internet.*","index:=0").Exist
vBrowserName = Window("title:=.*Internet.*","index:=0").GetROProperty ("title")
If Instr (vBrowserName, vTDString) Then
Do while Window("title:=.*Internet.*","index:=1").Exist
vBrowserName = Window("title:=.*Internet.*","index:=1").GetROProperty ("title")
If Instr (vBrowserName, vTDString) Then
Exit DO
Reporter.ReportEvent 2, "Closed CT1 Browser", "Closed Browser Session with name '" & vBrowserName & "'"
End If
Exit Do
Reporter.ReportEvent 2, "Closed Browser", "Closed Browser Session with name '" & vBrowserName & "'"
End If



** Happy Automating **


Anonymous said...

00 and rise and at this cost you have several features you must consider.
Red - this vibrant hue, about the other hand, is fiery and hot.
Another mark of quality in this chronometers is in the
few technicians that create them.

My web-site:

Software Development Company said...

The Article on QTP-IE-Close All Browsers is nice give detail information about it.Thanks for Sharing the information about Automation TESTING tools QTP.
mobile application testing