Closing all browsers

843 views
Skip to first unread message

Ashwini Khanna

unread,
Aug 31, 2008, 10:37:48 PM8/31/08
to MercuryQTP digest subscribers

Hey Dmitry,

I found this code on your blog-site to close all browsers. 

----------------------------------------------------------------

While Browser("CreationTime:=0").Exist
  Browser("CreationTime:=0").Close
Wend
----------------------------------------------------------------

This code works well and closes all instances of IE. But what question arises in my mind is - when I SPY on IE Browser I can't see any property called "CreationTime"; so how does it work?

Regards,

Ashwini


Srinivas Pavuluru

unread,
Sep 1, 2008, 2:41:09 AM9/1/08
to Mercu...@googlegroups.com, ashwi...@gmail.com
use the following function for close all browsers.. instead of creation time. 
 
Creation time is the one QTP to identify browser opened sequence..  Which is not displayed in properties.. If you record your script on more than one opened browser of similar names, you will see creation time property, by right clicking and viewing on recorded script browser objects.  Following function i found from QTP resources.   you can use it by calling function name within your script. 
 
Public function close_all_browsers()
dim bcount, bcount2
if(Browser("micclass:=Browser").exist) then
       Browser("micclass:=Browser").close
end if
wait(2) 'wait for closing browsers to close
bcount = 0
while (Browser("micclass:=Browser","location:=" & bcount).exist)
bcount=bcount+1
wend
if (bcount>1) then
'msgbox "Warning: " & bcount & " browser windows found"
end if
for bcount2 = 0 to bcount -1
    Browser("micclass:=Browser","location:=0").close
next 
end function

Thanks & Regards
Srinivas P

Dhanasekar Subramaniam

unread,
Sep 1, 2008, 8:03:33 AM9/1/08
to Mercu...@googlegroups.com
Srinivas,
   Here you have used Location instead of creation time ,why to complicate things if there is simple solution
The same can be done using the previous code given by Dmitry

While Browser("Location:=0").Exist
  Browser("Location:=0").Close
Wend

Ordinal identifier is the method used by QTP to index object with similar property,i have explained this at

http://testingideas.wordpress.com/2008/08/26/object-repository-and-descriptive-programming-in-qtp/

Regards,
Dhanasekar S.
http://testingideas.wordpress.com
---------------------------------------------------------
Let us make the World Greener
http://www.greenpeace.org/international/
-----------------------------------------------------------


2008/9/1 Srinivas Pavuluru <pavu...@gmail.com>



--


Jayadev

unread,
Sep 4, 2008, 5:22:51 AM9/4/08
to QTP - HP Quick Test Professional - Automated Software Testing
Hi All,
There is a lovely sibgle line code that closes all browsers

SystemUtil.CloseProcessByName("IEXPLORE.EXE")


Jayadev

On Sep 1, 11:41 am, "Srinivas Pavuluru" <pavul...@gmail.com> wrote:
> use the following function for close all browsers.. instead of creation
> time.
>
> Creation time is the one QTP to identify browser opened sequence..  Which is
> not displayed in properties.. If you record your script on more than one
> opened browser of similar names, you will see creation time property, by
> right clicking and viewing on recorded script browser objects.  Following
> function i found from QTP resources.   you can use it by calling function
> name within your script.
>
> *Public function close_all_browsers()
> dim bcount, bcount2
> if(Browser("micclass:=Browser").exist) then
>        Browser("micclass:=Browser").close
> end if
> wait(2) 'wait for closing browsers to close
> bcount = 0
> while (Browser("micclass:=Browser","location:=" & bcount).exist)
> bcount=bcount+1
> wend
> if (bcount>1) then
> 'msgbox "Warning: " & bcount & " browser windows found"
> end if
> for bcount2 = 0 to bcount -1
>     Browser("micclass:=Browser","location:=0").close
> next
> end function
> *
> Thanks & Regards
> Srinivas P
> On 8/31/08, Ashwini Khanna <ashwini...@gmail.com> wrote:
>
>
>
>
>
> > Hey Dmitry,
>
> > I found this code on your blog-site to close all browsers.
>
> > ----------------------------------------------------------------
>
> > While Browser("CreationTime:=0").Exist
> >   Browser("CreationTime:=0").Close
> > Wend
> > ----------------------------------------------------------------
>
> > This code works well and closes all instances of IE. But what question
> > arises in my mind is - when I SPY on IE Browser I can't see any property
> > called "CreationTime"; so how does it work?
>
> > Regards,
> > Ashwini- Hide quoted text -
>
> - Show quoted text -

Dmitry Motevich

unread,
Sep 4, 2008, 5:27:34 AM9/4/08
to Mercu...@googlegroups.com
I can remind you, that QTP can run tests on FireFox too.
I can be wrong, but I don't think that below "lovely sibgle line code" will close such browsers :))
--
Dmitry Motevich,
http://motevich.blogspot.com

Roman Zilber

unread,
Sep 4, 2008, 8:16:20 AM9/4/08
to Mercu...@googlegroups.com
This function very often crashes browser

Sreedhar Mallipeddi

unread,
Sep 5, 2008, 12:48:19 AM9/5/08
to Mercu...@googlegroups.com
HI All,

U can use this "SystemUtil.CloseDescendentProcesses" This will close all the browsers and files that QTP has opened.

Hope this shall work for u ....

Thanks,
Sreedhar
--
Mallipeddi Sreedhar
91-9848871279

Manjula Reddy

unread,
Sep 8, 2008, 8:16:46 AM9/8/08
to Mercu...@googlegroups.com
Hi,
 
Once you record any list of actions on any browser, then you can find the CreationTime property in Object Repository
 
Thanks,
Manjula

Srinivas Pavuluru

unread,
Sep 8, 2008, 1:16:16 PM9/8/08
to Mercu...@googlegroups.com, dhana...@gmail.com
Hi Dhanasekar
 

Thanks for simplifying the browser closing code; even this code works on both IE & Firefox.  I tried to execute the same logic on Google Chrome browser, QTP is identifying Google Chrome browser as windows object. Enclosing sample code,   I guess most of our QTP scripts will not work when we try executing on Google Chrome browser.  This is again going to be challenging task for us, if our applications try to supporting Google Chrome browser, then we need to think on modifying scripts.  I would like to share this information with you all.  Keep up the good work... All the best...

 

Window("Google Chrome").Activate
Window("Google Chrome").WinObject("Google").Click 373,50
Window("Google Chrome").WinObject("Google").Click 532,57
Window("Google Chrome").WinObject("Google").Click 588,51

 
Thanks & Regards
Srinivas P

Dhanasekar Subramaniam

unread,
Sep 8, 2008, 1:18:44 PM9/8/08
to Srinivas Pavuluru, Mercu...@googlegroups.com
Hi,
 We can't test on a browser which QTP doesn't support.
Thanks,
Dhanasekar S.

2008/9/8 Srinivas Pavuluru <pavu...@gmail.com>



--
Reply all
Reply to author
Forward
0 new messages