How to close all browsers in QTP?

This is very basic task to be done by the automation test engineer before starting the script execution.It's always better to kill/close
all related applications to avoid the unexpected behavior of QTP.
For example we can take a web based application.Assume that there are
n-number of windows has been opened for the same application. In such kind of scenarios, it's always better to close all windows and start from scratch.
 To achieve this we can use the QTP browser property "CreationTime".CreationTime indicates the order in which the browsers are opened.

Assume that we opened 5 browsers at 1.10,1.12,1.13,1.14 and 1.15.So, we will have the creation times as 0,1,2,3 and 4 for each browsers.The browsers can be closed by using the creation time.

Code Snippet:

01.While Browser("CreationTime:=0).Exist
02.Browser("CreationTime:=0)
03.Eend

Details of the above snippet:

01. Checks whether the first opened browser exists or not
02. Closes the first opened browser
03. Loop end

We can also close the browsers based on the mask.Assume that we opened n-number of Google sites.All browsers will have the URL as "Google.com"This is called mask. We can use the following code snippet to close the browsers based on the mask.

Dim Url, CreationTime,Mask
Mask="Google.com"
CreationTime="0"
While Browser("CreationTime:="&CreationTime).Exist
Url=Browser("CreationTime:="&CreationTime).GetROProperty("Url")
'check whether Url contains the mask
If InStr(Url,Mask)>0 Then
'Close the current browser
Browser("CreationTime:="&CreationTime).close
Else
CreationTime=CreationTime+1
End If
Wend

Using the above code snippet we can close the browsers dynamically by mask.
SHARE

About அமரகோசம்

    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment