Invalid Browser Count

Ranorex Studio, Spy, Recorder, and Driver.
Praveen597
Posts: 27
Joined: Sat Aug 27, 2011 9:41 am

Invalid Browser Count

Post by Praveen597 » Thu Sep 22, 2011 2:31 pm

Hi All,
Here is my code to get the number of currently running browsers on the screen,

IList<Ranorex.WebDocument> AllBrowsers = Host.Local.FindChildren<Ranorex.WebDocument>();
int BrowCount = AllBrowsers.Count;
Console.WriteLine(BrowCount);

I am getting answer as 1, even if no browsers are currently under running state.

And getting answer as 2, if there exists one browser on the screen.

What I mean to say is, every time I am getting answers as (Number of currently running browsers + 1).
Is there any solution for this ...?

User avatar
Ciege
Posts: 1336
Joined: Thu Oct 16, 2008 6:46 pm
Location: Arizona, USA

Re: Invalid Browser Count

Post by Ciege » Thu Sep 22, 2011 3:23 pm

What version of windows?

Do you have any minimized or hidden browsers open?
Do you have any file explorers open?
Do you have any widgets open?

Many things in Windows are run within a "browser" context so if they are open even if they are not visible they can be counted as a browser object.

With the 1 browser that the piece of code is finding, can you return the properties of the browser and see what it actually is (like get the url, etc...)
Also, use RanorexSpy to browse your machine and look to see what is getting reported as a browser.
If this or any response has helped you, please reply to the thread stating that it worked so other people with a similar issue will know how you fixed your issue!

Ciege...

Praveen597
Posts: 27
Joined: Sat Aug 27, 2011 9:41 am

Re: Invalid Browser Count

Post by Praveen597 » Fri Sep 23, 2011 11:14 am

I am running the script in both Windows 7 as well as Windows XP 2


Do you have any minimized or hidden browsers open?
No, I don't think so

Do you have any file explorers open? No
Do you have any widgets open? No

I am trying all possibilities but filed to reach the target...!

User avatar
Support Team
Site Admin
Site Admin
Posts: 12145
Joined: Fri Jul 07, 2006 4:30 pm
Location: Houston, Texas, USA
Contact:

Re: Invalid Browser Count

Post by Support Team » Fri Sep 23, 2011 11:24 am

Hi,

You are searching for all Ranorex.WebDocument and these adapter represents DOM Object and not browser instances. If you open Ranorex Spy and check how many DOM Objects inside this tree you will notice that the count fits into your count.

Regards,
Peter
Ranorex Team

Praveen597
Posts: 27
Joined: Sat Aug 27, 2011 9:41 am

Re: Invalid Browser Count

Post by Praveen597 » Mon Sep 26, 2011 11:53 am

Thank you Peter,

Then what to do to get all the currently available browser count...?:?:

Regards,
Praveen

User avatar
Support Team
Site Admin
Site Admin
Posts: 12145
Joined: Fri Jul 07, 2006 4:30 pm
Location: Houston, Texas, USA
Contact:

Re: Invalid Browser Count

Post by Support Team » Mon Sep 26, 2011 1:44 pm

Hi

You could use following code
var iexplore = System.Diagnostics.Process.GetProcessesByName("iexplore");
var firefox = System.Diagnostics.Process.GetProcessesByName("firefox");
				
Console.WriteLine("IE: " + (iexplore.Length));
Console.WriteLine("Firefox: " + (firefox.Length));
to check how many browsers are currently running.

Regards,
Peter
Ranorex Team

Praveen597
Posts: 27
Joined: Sat Aug 27, 2011 9:41 am

Re: Invalid Browser Count

Post by Praveen597 » Tue Sep 27, 2011 5:59 am

Hey Peter,

This code is absolutely fine since I am using the same code I know it very well.
But my aim is to get all the browser's count regardless of browser type. :?:

The drawback of the present code is, we have to write a separate code for each and every browser.
I feel this is not that much generic........ :!:
We need to handle all type of browsers (or atleast for some max extent of browsers) in a single function.

I think now you got my intentions :)

User avatar
Support Team
Site Admin
Site Admin
Posts: 12145
Joined: Fri Jul 07, 2006 4:30 pm
Location: Houston, Texas, USA
Contact:

Re: Invalid Browser Count

Post by Support Team » Tue Sep 27, 2011 2:23 pm

Hi,

Would it be possible to post or send me a full snapshot of you host, when you try to receive the DOM Objects. I think there are one or two embedded in an application and maybe we find an RxPath to filter them out.

Thanks in advance.

Regards,
Peter
Ranorex Team

Praveen597
Posts: 27
Joined: Sat Aug 27, 2011 9:41 am

Re: Invalid Browser Count

Post by Praveen597 » Tue Sep 27, 2011 3:24 pm

Hi Peter,

Let me describe my TestCase Scenario:

For Eg,
We have a facebook login option in our application. Once we click on that button, a new window will open for facebook login, upon giving the valid credentials it'll allow us to access facebok albums .

Now, for any reason , if it fails to access the albums or if we enter a invalid credentials then we need to capture both the browser images . In reality we failed to capture both the browser images.

Help me out dude....!!

User avatar
Ciege
Posts: 1336
Joined: Thu Oct 16, 2008 6:46 pm
Location: Arizona, USA

Re: Invalid Browser Count

Post by Ciege » Tue Sep 27, 2011 4:16 pm

Praveen597 wrote:Hey Peter,

This code is absolutely fine since I am using the same code I know it very well.
But my aim is to get all the browser's count regardless of browser type. :?:

The drawback of the present code is, we have to write a separate code for each and every browser.
I feel this is not that much generic........ :!:
We need to handle all type of browsers (or atleast for some max extent of browsers) in a single function.

I think now you got my intentions :)
Well, you can write one method that incorporates the count for all browser types then. Have that method return a result to you of a list of browsers or a count or whatever you want. If you write the method once you can reuse that method wherever you want in you testing...
If this or any response has helped you, please reply to the thread stating that it worked so other people with a similar issue will know how you fixed your issue!

Ciege...

Praveen597
Posts: 27
Joined: Sat Aug 27, 2011 9:41 am

Re: Invalid Browser Count

Post by Praveen597 » Tue Sep 27, 2011 4:51 pm

Oh Ciege,

So you want me to write a piece of code for IE, FF, Chrome, Safari, etc....

Am I right....??

User avatar
Ciege
Posts: 1336
Joined: Thu Oct 16, 2008 6:46 pm
Location: Arizona, USA

Re: Invalid Browser Count

Post by Ciege » Tue Sep 27, 2011 5:03 pm

Sure, why not... One method that does it all and returns exactly the information you want... It's not difficult. You get to make it do exactly what you want. You write it once and reuse it however many times you want. Any modifications, fixes, changes, etc... are all done in only one place.

It is clearly, in my mind, the best path to take...

Pseudo Code:

Code: Select all

public static list[] GetListOfOpenBrowsers()
try
{
//Get list of IE browsers then add to the list
for each IE browser
{ mylist.add IE Browser}

//Get list of FF browsers then add to the list
for each FF browser
{ mylist.add FF Browser}

etc...

return mylist
}
catch exception
{return null}
If this or any response has helped you, please reply to the thread stating that it worked so other people with a similar issue will know how you fixed your issue!

Ciege...

Praveen597
Posts: 27
Joined: Sat Aug 27, 2011 9:41 am

Re: Invalid Browser Count

Post by Praveen597 » Wed Oct 05, 2011 12:21 pm

Hi Ciege,

Is there any predefined method/function to count the number of browsers currently running irrespective of browser type..?

User avatar
Ciege
Posts: 1336
Joined: Thu Oct 16, 2008 6:46 pm
Location: Arizona, USA

Re: Invalid Browser Count

Post by Ciege » Wed Oct 05, 2011 4:37 pm

Not that I am aware of... You need to write the code yourself.
If this or any response has helped you, please reply to the thread stating that it worked so other people with a similar issue will know how you fixed your issue!

Ciege...

Praveen597
Posts: 27
Joined: Sat Aug 27, 2011 9:41 am

Re: Invalid Browser Count

Post by Praveen597 » Mon Oct 10, 2011 11:14 am

Thank You.