Strange RanorexPath expression error

Class library usage, coding and language questions.
bbv_philippdolder
Posts: 10
Joined: Thu Nov 26, 2009 6:54 am

Strange RanorexPath expression error

Post by bbv_philippdolder » Wed Jan 20, 2010 7:49 am

Hello

I have the following problem: I have a screen where I want to wait for the 'Close' button to become active before going on with my test scenario.

I use the following code for this:
public bool WaitForCompletion(int timeoutSeconds)
{
const int WaitTime = 10;
int timePassed = 0;
while (timePassed <= timeoutSeconds)
{
this.Form.Self.Activate(); // <- strange behavior from this line

if (this.Form.Close.Enabled)
{
this.TakeScreenshot();
return true;
}

Delay.Seconds(WaitTime);
timePassed += WaitTime;
}

this.TakeScreenshot();
return false;
}

But then I get the following exception:
Ranorex.ElementNotFoundException: No element found for path '/form[@controlname='MainForm']/container[@controlname='WorkAreaPanel']/element/container[@caption='Workplace']/tabpage/tabpagelist/tabpage/button[@accessiblename='Close']/container[@controlname='WorkAreaPanel']/element/container[@caption='Workplace']/tabpage/tabpagelist/tabpage/button[@accessiblename='Close']' within 5000ms.

It seems that it messes up the RanorexPath which is, in RanorexSpy from where I have generated the code:
"/form[@controlname='MainForm']" for the MainForm and the Child is the Close Button with container[@controlname='WorkAreaPanel']/element/container[@caption='Workplace']/tabpage/tabpagelist/tabpage/button[@accessiblename='Close']

What I found out is that when I use "this.Form.Self.Activate();" the RanorexPath expression gets messed up. I think this is a bug in the RanorexPath Builder that adds the relative part from the close button a second time.

EDIT: When I don't use Activate() I get the following exception:
Ranorex.ElementNotFoundException: No element found for path 'container[@controlname='WorkAreaPanel']/element/container[@caption='Workplace']/tabpage/tabpagelist/tabpage/button[@accessiblename='Close']' within 10s.

Which in my opinion cannot be found because it does not search for the absolute path including the "/form[@controlname='MainForm']" part?!

Is there another way to ensure that the form is active? I thought it should not be necessary for the form to be active when I want to check whether a button is enabled or not but Ranorex couldn't find it when it was not the active window. So I tried it with the Activate() method.

Any hints or suggestions?

Best Regards
Philipp Dolder

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

Re: Strange RanorexPath expression error

Post by Support Team » Wed Jan 20, 2010 9:51 am

Which Ranorex version do you use? Could you please post the code for this class? Because it seems this is not an ordinary repository, but a custom class of yours.

By the way, you know that your WaitForCompletion method could throw an exception if the "Close" button is not there yet, when the method is called? If the "Close" button is always there in your application and your just waiting for it to get enabled, then everything's ok. However, if you wait for the "Close" button to appear and the time to wait is longer than the timeout defined for the "Close" button, Ranorex won't be able to find it at the first time and the line "this.Form.Close.Enabled" will throw an ElementNotFoundException. Could this be the actual problem?

Regards,
Alex
Ranorex Support Team
.
Image

bbv_philippdolder
Posts: 10
Joined: Thu Nov 26, 2009 6:54 am

Re: Strange RanorexPath expression error

Post by bbv_philippdolder » Wed Jan 20, 2010 10:51 am

I'm using latest and greatest Ranorex 2.2.1. Furthermore I'm using NUnit 2.5.3 with ReSharper to run the tests during development, I've also set the RequiresSTA attribute on my test fixture.

I attached the 2 source files in the zip file. PcrProcessing.cs is the class containing the WaitForCompletion method. and PcrProcessRepository.cs contains the repository class generated with the Ranorex Spy.

I'm aware of the issue you mentioned. In our system the Button is visible before calling WaitForCompletion, but disabled. I wait for it to become enabled only.

What made me prick my ears was the fact that depending on commenting out the call to Activate() there was a different RanorexPath that was told me could not be found.

Thanks for your advice
Philipp
Attachments
SourceCode.zip
The source files
(1.84 KiB) Downloaded 211 times

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

Re: Strange RanorexPath expression error

Post by Support Team » Wed Jan 20, 2010 5:16 pm

I checked our internal bug database and found a bug in V2.2.1 that messes up the RanoreXPath used in the exception text by concatenating the relative path of an item twice to the absolute path of the folder; that happens only if the folder is already cached. That bug perfectly describes what happens with your exception messages - the call to "Form.Activate" causes the "Form" to be cached on the next access, thus causing the exception text to be messed up.

This bug is fixed in the upcoming version 2.2.2, however, it has no influence on the path that is searched for, just on the exception message. You can easily check that by turning of the "Use Cache" property of the "Form" folder in the repository. Then the exception text should always have the right path in it, no matter if you call "Activate" or not. (BTW, the "Activate" call should usually not be needed at all, it just brings the corresponding form into the foreground.)

There seems to be something wrong with the RanoreXPath of your "Close" button. Please, spy the button (using Ranorex Spy) when it is disabled. Is the path the same as the one when the button is enabled? If it isn't, then try to store the "Close" button element in a local variable and use this variable in your loop. That way Ranorex won't search for the RanoreXPath again, but will directly use the button element (that will also improve performance), for example:
Button closeButton = this.Form.Close;
while (timePassed <= timeoutSeconds)
{
    ...
    if (closeButton.Enabled)
    ...
}
Regards,
Alex
Ranorex Support Team
.
Image

bbv_philippdolder
Posts: 10
Joined: Thu Nov 26, 2009 6:54 am

Re: Strange RanorexPath expression error

Post by bbv_philippdolder » Wed Jan 20, 2010 6:21 pm

When I spy the disabled button after loading my repository in the Ranorex Spy the button gets highlighted as expected. But when I execute it in my code with the generated repository code it can't be found, not even if the button is in the same state (disabled) as when spying with the Spy.

Because the process is taking quite a while before the Close button gets enabled I will run it over night and spy it the next morning to post here what I found out.

Best regards
Philipp

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

Re: Strange RanorexPath expression error

Post by Support Team » Wed Jan 20, 2010 6:46 pm

Could you post the complete report file generated by your code? Are there any warnings in the report?
Do you have the STAThread attribute applied to your Main methode?

Regards,
Alex
Ranorex Support Team
.
Image

bbv_philippdolder
Posts: 10
Joined: Thu Nov 26, 2009 6:54 am

Re: Strange RanorexPath expression error

Post by bbv_philippdolder » Mon Jan 25, 2010 7:16 am

I found out the Problem:

I added the "RequiresSTA" attribute to my NUnit Fixture but ReSharper was not applying it correctly when I ran the tests from within Visual Studio. After using the NUnit UI to run the tests everything is working fine and I can wait for the button.

I think I was misleaded to hunt for a false error because of the exception message I got in the very beginning.

What makes me uncertain is that I remember that we had similar tests running with ReSharper that worked fine when we were evaluating Ranorex.

Anyway, thanks for your support.

Regards,
Phil

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

Re: Strange RanorexPath expression error

Post by Support Team » Mon Jan 25, 2010 9:58 am

bbv_philippdolder wrote:What makes me uncertain is that I remember that we had similar tests running with ReSharper that worked fine when we were evaluating Ranorex.
The STAThread attribute (or RequiresSTA for NUnit) is only required to communicate with controls of certain technologies, not for every control. I.e. even without using STA threads your automation may work correctly, if you by chance do not come accross elements (from flavors like MSAA, Web, or UIAutomation) that need STA threads to work.

Regards,
Alex
Ranorex Support Team
.
Image