Ranorex cannot find element when ran from test runner

Technology specific object identification, supported applications, web technologies, and 3rd party controls.
WajdaW
Posts: 75
Joined: Wed Jan 05, 2011 6:45 pm

Ranorex cannot find element when ran from test runner

Post by WajdaW » Mon Dec 26, 2011 9:51 am

I have following problem. When I start my test using nunit as my test runner Ranorex sometimes cannot find element. But when I saw that test hanging for a while, I opened my repo and tried to highlight element with ranorex spy, and I succeeded.
Strange thing is that it is the same repo and same element.
I think that maybe something with my test runner configuration isn't right. As of configuration, I configured nunit this way:

1. I added at my app.config this part:

<configuration>
<configSections>
<sectionGroup name="NUnit">
<section name="TestRunner" type="System.Configuration.NameValueSectionHandler"/>
</sectionGroup>
</configSections>
<NUnit>
<TestRunner>
<add key="ApartmentState" value="STA"/>
</TestRunner>
</NUnit>
</configuration>

2. I added at nunit.exe.config, nunit-agent.exe.config, nunit-console.exe.config this part:

<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0"/>
<supportedRuntime version="v2.0.50727"/>
</startup>

I'm using .NET 4.0

How I should configure nunit so it can find elements every time?

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: Ranorex cannot find element when ran from test runner

Post by Support Team » Tue Dec 27, 2011 3:18 pm

Hi,

Just a hunch, do you start NUnit as administrator? Maybe just disable the UAC if you use Win7. Is the full .Net 4.0 Framework available on this machine?

Regards,
Peter
Ranorex Team
.
Image

WajdaW
Posts: 75
Joined: Wed Jan 05, 2011 6:45 pm

Re: Ranorex cannot find element when ran from test runner

Post by WajdaW » Tue Dec 27, 2011 11:41 pm

UAC is turned off on my win 7 and that is my dev machine, so there is full .NET 4.0 framework.
I haven't been starting nunit explicitly as admin before as I am admin at that machine. Now I have explicitly right clicked and and chosen 'Run as administrator' option. But it seems that problem persists, it still cannot find this element from time to time.

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: Ranorex cannot find element when ran from test runner

Post by Support Team » Wed Dec 28, 2011 10:08 am

WajdaW wrote:But it seems that problem persists, it still cannot find this element from time to time.
And the test is working alright if you are not using NUnit to start it?

Please, set the report level for the test to "Debug" (see Ranorex User Guide).
Can you post the Ranorex report generated when running the test using NUnit?
Are there any warning or technology limitations shown in the report?

Can you create a snapshot of the problematic controls using the following automation module and post it afterwards, please?
http://www.ranorex.com/forum/create-sna ... t2447.html

Regards,
Alex
Ranorex Team
.
Image

WajdaW
Posts: 75
Joined: Wed Jan 05, 2011 6:45 pm

Re: Ranorex cannot find element when ran from test runner

Post by WajdaW » Wed Dec 28, 2011 2:09 pm

Support Team wrote:And the test is working alright if you are not using NUnit to start it?
I always use NUnit to start the test because I only use ranorex automation API, and I'm writing my tests in code with this API. But when I start test I set timeout at 3 minutes for this element. And since it always finds element in first few seconds I know when some time passes that ranorex will not be able to find element, and than I started Ranorex Spy while my test was running and I was able to find that element when I opened my ranorex reporisory file in spy. That is strange to me since I generate repository code from ranorex repository and that two paths (one executing in test, and other in repository in ranorex spy) are identical.

Further, I don't know how to set this debug mode since I only write tests using ranorex automation API, nothing else.

I created two snapshots, one when element is found and other when it isn't.

More info, I'm using some .NET http request async calls, and my form is shown when async callback is called, so it's from another thread, but I than dispatch form show to thread of my main app since I want from this form to be modal. Maybe this is causing problems. Here is that code:

public void ShowView()
{
if (threadId.Id != Thread.CurrentThread.ManagedThreadId)
{
Action a = new Action(ShowView);
dispatcher.Invoke(a, null);
}
else this.ShowDialog();
}

Dispatcher is bound to main thread.

Element that I'm failing to find is username textbox. I haven't found any pattern in which form is found or not so far.

Regards,
Vladimir
Attachments
notfound.rxsnp
(196.4 KiB) Downloaded 190 times
found.rxsnp
(189.77 KiB) Downloaded 199 times

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: Ranorex cannot find element when ran from test runner

Post by Support Team » Thu Dec 29, 2011 12:07 pm

WajdaW wrote:Further, I don't know how to set this debug mode since I only write tests using ranorex automation API, nothing else.
If you do not use the Ranorex test suite, just set the the current report level and then post the resulting report, please:
Report.CurrentReportLevel = ReportLevel.Debug;
WajdaW wrote:I created two snapshots, one when element is found and other when it isn't.
What is the difference when the element is found and when it is not found? Are you starting the execution differently? Or is it just random?

From the snapshots it looks like Ranorex cannot load most of the .NET DLLs used in your application under test (AUT). This might be an issue of NUnit or running the executable from a network drive or without the required security rights. Please, see following troubleshooting guide:
http://www.ranorex.com/support/user-gui ... html#c3250

Regards,
Alex
Ranorex Team
.
Image

WajdaW
Posts: 75
Joined: Wed Jan 05, 2011 6:45 pm

Re: Ranorex cannot find element when ran from test runner

Post by WajdaW » Thu Jan 05, 2012 1:30 pm

These files were generated when I ran tests.

I couldn't upload second one, so here it is: http://www.megaupload.com/?d=6GLDRXWY
What is the difference when the element is found and when it is not found? Are you starting the execution differently? Or is it just random?
There is no difference, I start group of tests, and randomly some of them fails because of not finding this element, but element is there, I can see it and find it with standalone ranorex spy.

I read about those troubleshooting with WinForms, all of that I already satisfy.
Attachments
Ranorex.rxlog
(1.22 KiB) Downloaded 171 times

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: Ranorex cannot find element when ran from test runner

Post by Support Team » Thu Jan 05, 2012 2:16 pm

Well, if it always works in Ranorex Spy, my guess is that it has something to do with the way NUnit load assemblies for test runs. E.g. if the DLLs within your AUT changes, NUnit might not reload the assemblies correctly.

There are a few settings you can change in NUnit regarding "Assembly Isolation" and "Assembly Reload". Could you try changing the settings to:
  • Assembly Isolation -> Run tests in a single sepearte process
  • Assembly Reload -> Check "Reload before each test run"
Regards,
Alex
Ranorex Team
.
Image

WajdaW
Posts: 75
Joined: Wed Jan 05, 2011 6:45 pm

Re: Ranorex cannot find element when ran from test runner

Post by WajdaW » Thu Jan 05, 2012 5:31 pm

Support Team wrote:Assembly Isolation -> Run tests in a single sepearte process
Assembly Reload -> Check "Reload before each test run"
I set those settings and now all of my tests failed because username field wasn't found.

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: Ranorex cannot find element when ran from test runner

Post by Support Team » Mon Jan 09, 2012 5:15 pm

WajdaW wrote:I set those settings and now all of my tests failed because username field wasn't found.
Did you investigate that problem a little further?
Have you tried other combinations for the settings in "Assembly Isolation" and "Assembly Reload"?

Regards,
Alex
Ranorex Team
.
Image

WajdaW
Posts: 75
Joined: Wed Jan 05, 2011 6:45 pm

Re: Ranorex cannot find element when ran from test runner

Post by WajdaW » Fri Jan 13, 2012 10:34 am

Yes, I figured out that when I changed assembly isolation settings that my RxPath changed as well. I changed RxPath accordingly but than tests failed on other elements.
I'm now have a lot of other stuff to do that have higher priority. I have few ideas of maybe trying to remove @processname attribute from my RxPaths.
I have one question, would it migration to WPF components solve problem? Do you have maybe better integration with these components?

I'l try all of this later, I don't have time for this now.

regards,
Vladimir Vajda

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: Ranorex cannot find element when ran from test runner

Post by Support Team » Mon Jan 16, 2012 5:34 pm

WajdaW wrote:Yes, I figured out that when I changed assembly isolation settings that my RxPath changed as well.
Could you name a few of those changes, please? It could be that due to NUnit restrictions some controls could not be recognized correctly before your changes to the NUnit settings.
WajdaW wrote:I have one question, would it migration to WPF components solve problem? Do you have maybe better integration with these components?
There is no "better integration" with WPF components, it is just different. The support of WinForms controls through Ranorex is one of the best in the industry.
The problem with every technology is to get the setup right. If there is some problem in the object recognition caused by restrictions from the environment (like NUnit), every technology will fail. That's why it is very important to get the initial setup for your tests right, i.e. to initially get Ranorex to correctly identify your controls.

Regards,
Alex
Ranorex Team
.
Image