Too many browsers open causing different behaviour

Ask general questions here.
User avatar
Aracknid
Posts: 388
Joined: Tue Aug 10, 2010 3:23 pm
Location: Toronto, Ontario, Canada

Too many browsers open causing different behaviour

Post by Aracknid » Thu Jul 28, 2011 9:49 pm

Hi,

I'm working on a framework that allows me to log into the various components of my app multiple times as different users. Our app has different web site apps with different functionality. So I can log into web site 1 as user 1, web site 2 as user 2, etc... Each launches a browser window (I've disabled tabs). I've currently limited it to allowing 2 different logins per site, and there are 4 different sites, so I can have up to 8 different browser windows open.

Here's the problem: When I log in with only 1, 2 or 3 browsers, no matter which sites (I've tried different combos) everything is working fine. However, when I have 4 or more I start running into issues with being unable to find the elements.

So for example say I've logged into all 4 sites once (and have 4 different browser windows). Now that all the launching has been done, I want to click the log out button on one of the browsers. I've got code similar to this in a class/procedure to handle clicking buttons (I left out a bunch of code):
Public Function Click(sRxPath as string, oParent as Ranorex.Core.Element)
    Dim MyControl as Ranorex.Unknown = Nothing
    Try
        MyControl = oParent.FindSingle(sRxPath, 30)
        MyControl.EnsureVisible
        MyControl.Click
        Return True
    Catch e as exception
        debug.print(e.message)
        Return False
    End Try
End Function
When I call this function, I'll pass something like this:
SessionControls.Click(".//td[@id='lnkLogoff']", oBrowserWebDoc1)
And oBrowserWebDoc1 is the Web Document that contains this log off button for one of the web sites.

So, when I run 1, 2 or 3 browsers at the same time, this code works fine and everything works when I want to log out. However, when I launch more browsers and call the same function, it cannot find the button. I thought maybe it was just not finding it within the 30 seconds I've allocated, so I jacked it up and that didn't help.

Any thoughts? I'm using 3.0.3.

Aracknid

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

Re: Too many browsers open causing different behaviour

Post by Support Team » Fri Jul 29, 2011 2:55 pm

The solution to that problem might be quite simple: In your code you have a hard-coded timeout of 30 milliseconds. That might be enough to find the element if only 3 processes are running at the same time, but with more the timeout will surely be too small (I'm surprised it works with 3 concurrent processes).
That's particularly true if you pass RanoreXPaths containing expensive operators like "//" which means that all descendants of the current element are searched.

In addition, performing two or more Click operations at the same time can also cause problems, since the two mouse moves can influence each other. See this thread for more information:
http://www.ranorex.com/forum/concurrent ... t1979.html

Regards,
Alex
Ranorex Team

User avatar
Aracknid
Posts: 388
Joined: Tue Aug 10, 2010 3:23 pm
Location: Toronto, Ontario, Canada

Re: Too many browsers open causing different behaviour

Post by Aracknid » Fri Jul 29, 2011 7:27 pm

Perhaps I don't understand (that's very likely it... :) ), or maybe I mislead you in my post. I'm not actually running multiple Ranorex scripts at the same time, nor am I clicking multiple things at the same time. My 1 script simply launches IE and goes to a web site and stores the DOM as an object, say oBrowserWebDoc1. Then it launches IE again and logs in as a different user and stores that DOM as oBrowserWebDoc2. Etc...

So I have oBrowserWebDoc1, oBrowserWebDoc2, oBrowserWebDoc3, and oBrowserWebDoc4.

After all the launches (I don't yet have any code to do anything except log out), I'll just do this which executes one after the other (not at same time):

SessionControls.Click(".//td[@id='lnkLogoff']", oBrowserWebDoc1)
SessionControls.Click(".//td[@id='lnkLogoff']", oBrowserWebDoc2)
SessionControls.Click(".//td[@id='lnkLogoff']", oBrowserWebDoc3)
SessionControls.Click(".//td[@id='lnkLogoff']", oBrowserWebDoc4)

While in the sub Click, nothing happens other than what you see in my previous post, so there is only one click at a time.

I tried putting the full path and it didn't help. If I increase the time (to 120 seconds), I get this message from VS2010 debugger:

ContextSwitchDeadlock was detected
The CLR has been unable to transition from COM context 0x1b7c00 to COM context 0x1b7d70 for 60 seconds. The thread that owns the destination context/apartment is most likely either doing a non pumping wait or processing a very long running operation without pumping Windows messages. This situation generally has a negative performance impact and may even lead to the application becoming non responsive or memory usage accumulating continually over time. To avoid this problem, all single threaded apartment (STA) threads should use pumping wait primitives (such as CoWaitForMultipleHandles) and routinely pump messages during long running operations.

Actually, what I find weird is that when only 3 browsers are running, it finds the buttons in about 1 second with the ".//" path and generally works super fast.

Aracknid.

User avatar
Aracknid
Posts: 388
Joined: Tue Aug 10, 2010 3:23 pm
Location: Toronto, Ontario, Canada

Re: Too many browsers open causing different behaviour

Post by Aracknid » Fri Jul 29, 2011 7:48 pm

Just a follow-up -I googled the "ContextSwitchDeadlock was detected" error and found out how to turn it off in the "Debug > Exceptions", so instead of this, I get a proper timeout of 120 seconds. I changed it to 5 minutes, and still it couldn't find it.

User avatar
Aracknid
Posts: 388
Joined: Tue Aug 10, 2010 3:23 pm
Location: Toronto, Ontario, Canada

Re: Too many browsers open causing different behaviour

Post by Aracknid » Mon Aug 08, 2011 3:20 pm

Any thoughts on this? Still hoping for a solution if there is one.

Aracknid