Close All Browser Except OLD One QTP VB

Posted by rajivkumarnandvani on May 13, 2009

Hi All,

Some time we required that Only OLD open Browser Window( Only for IE) will remain Open and rest of all shall be closed during QTP scripting. Here is the Function which will close the all open Browser except OLD Open browser (Work only for Internet Explorer using QTP)

Public function fn_CloseAllBrowserRemainingOLD

rem create Browser description object
Set brwsr=Description.Create
Set obj=Desktop.ChildObjects(brwsr)
browserCount= obj.count
Set obj=nothing
If  browserCount >1  Then
Set obj=Desktop.ChildObjects(brwsr)
browserCount= obj.count
Set obj=nothing
loop  until  browserCount =1
End If

End Function


6 Responses to “Close All Browser Except OLD One QTP VB”

  1. Bharath M said

    Hi rajivkumarnandvani ,

    Too good this function.Thanks alot.

    Bharath M

  2. Thanks

  3. Poornima said

    Hi Rajiv…………..
    THis function is good. It really helped me. I’m doing a bit research on QTP
    Thanks for the valuable function

  4. Thanks a lot

  5. kishore said

    Thanks Rajiv.

    I need solution for my below problem. Please shed some light and provide your solution at the earliest.

    Dear All,

    Hope you are doing well. I am facing a silly problem.

    scenario is like this:
    1. On a webpage, I need to add few attachments with extensions like .txt, .doc, .xls, .jpg, .bmp etc
    2.After that when I click on those links (example: samplefile.txt or samplefile.bmp) for some of the filetypes, new browser is getting opened (for all image files and text files, new browser gets opened)
    3.I need to close this browser –this is the verification procedure to validate that the file has been opened.

    I tried with If Browser(“CreationTime:=1”).exist then Browser(“CreationTime:=0”).close

    On my application, 1st browser is QCenter 2nd will be my application and this 3rd browser gets opened when I click on these image files, new browser gets opened, it has to be closed.

    I want to close the recently opened browser.

    New browser will open for sample.txt, sample.bmp, sample.pdf. sample.gif, sample.jpg files alone.

    In that case, how do I give the Expected_FileName value?

    In the datatable, I have the paths of the filenames

    I am making use of For i=1 to Datatable.Getsheet(“sheetname”).Getrowcount

    Inside the loop, I am attaching files and opening those attachments.
    I need to throw a reporter.pass message or fail message once these files are viewable, then this is pass else fail

    I also tried with DP, by creating Desktop.childobjects etc, still didnt work.

    Please provide me solutions ASAP.

  6. Hi Kishore,

    What problem you facing while using Desktop.childobject method.
    I think you can do this by following logic.first count the total browser opened. after that in loop statement you need to check each browser URL OR TEXT property if Browser().getroproperty(url) or text something like that match with QC browser url or first browser that is not newly open browser then do not close the browser else close the browser.

    Let me know this clear to you or not

    Thanks and best of luck

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: