Help with reliability of searching for a form...

Ask general questions here.
User avatar
Ciege
Posts: 1336
Joined: Thu Oct 16, 2008 6:46 pm
Location: Arizona, USA

Help with reliability of searching for a form...

Post by Ciege » Fri Jul 17, 2009 5:53 pm

I have a method that searches for forms that are children of a parent form. The problem is that after some time of testing (usually at least an hour) the method quits working. In other words, the Ranorex FindSingle fails to find the form. When this happens I can see the form is there visually and after the exception occurs I can use Spy and find the form.

Here is the code:

Code: Select all

private static Ranorex.Form WaitForFormOfForm(Ranorex.Form ParentRanorexFormName, string strFormName, int Timeout)
{
    /************************************************************************
     * Function         : WaitForFormOfForm(Ranorex.Form ParentRanorexFormName, string strFormName, int Timeout)
     *
     * Description      : This function will wait for a form with a specific  
     *                  :  control name that is a child of a parent form to appear.
     *                         
     * Parameters       : ParentRanorexFormName - Parent form to look in
     *                  : strFormName       - Control name of the form to find
     *                  : Timeout           - Time (in seconds) to wait for the window
     *                                      -  before giving up.
     *                  
     * Return Type      : Ranorex.Form
     * 
     * Return Value     : Ranorex.Form Object for success, null for failure
     * 
     * Revision History
     * Date       : Author                    : Reason/Change
     * ---------- : ------------------------- : ------------------------------
     * 06/09/2009 : Chris Gendreau            : Initial Creation 
    ************************************************************************/
    Ranorex.Form HDForm = null;

    Report.Debug("Waiting for form: " + strFormName + " within form: " + ParentRanorexFormName.Element.GetAttributeValue("ControlName").ToString());
    try
    {
        HDForm = ParentRanorexFormName.FindSingle(".//form[@controlname='" + strFormName + "']", Timeout * 1000);
        HDForm.Activate();
        Thread.Sleep(1000);
        return HDForm;
    }
    catch (RanorexException e)
    {
        try
        {
            Thread.Sleep(5000);
            HDForm = ParentRanorexFormName.FindSingle(".//form[@controlname='" + strFormName + "']", Timeout * 1000);
            HDForm.Activate();
            Thread.Sleep(1000);
            return HDForm;
        }
        catch (RanorexException ex)
        {
            Report.Debug("Unable to find form: " + strFormName + " within form: " + ParentRanorexFormName.Element.GetAttributeValue("ControlName").ToString());
            return null;
        }
    }
} //End WaitForFormOfForm
I added the second try/catch block within the first catch to re-check automatically for the forms existence. Not sure if this has helped or not, but obviously my wait is doubled when it can't find the form the first time.

Can you offer any suggestions as to how to increase the reliability of this method?

Thanks!
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...

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

Re: Help with reliability of searching for a form...

Post by Ciege » Fri Jul 17, 2009 10:42 pm

Just wanted to add that when I call this method I am usually using a timeout of 30 seconds, which should be enough I would assume. I will modify my second FindSingle in the second try/catch block to a timeout of

Code: Select all

(timeout * 2) * 1000
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...

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

Re: Help with reliability of searching for a form...

Post by Support Team » Tue Jul 21, 2009 10:17 am

Hi ciege,
it`s not necessary to check 2nd time in the catch block. Why you don`t set the search timeout at the first FindSingle to the final value? It does the same.

About your FindSingle error after a while:
Weird!
Could you give more detailed information about your application and exactly what you are doing. Timing issues are hard to find anyway.
It looks like that your AUT is an MDI application. Right?

Regards,
Christian
Support Team

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

Re: Help with reliability of searching for a form...

Post by Ciege » Tue Jul 21, 2009 4:14 pm

The second catch/block sometime helps but not always. It appears that sometimes if the find begins before the form is available, it will fail even if the form becomes available before the find timeout is exceeded. It doesn't really seem to matter if I extend my timeout to 60 or even 120 seconds, if it's going to fail it will fail regardless of the form appearing before the timeout.

I use a variable timeout because some forms that I may search for with this method are direct children of the desktop and can be found quite quickly. Usually I use a 30 second delay on forms that are further down the food chain than the desktop.

The AUT does use several forms at once so I believe the answer to your MDI question is yes. The AUT is written in C# with several DevExpress components thrown in.

As to what I am doing... I am opening and reading data from several forms. Sometimes I need to click a button or a linked cell in one form that triggers another form to open. I need to wait for that form to open before I can proceed and do my stuff on the next form and so on... This particular automation script is designed to run for several hours (at least 4 but I have yet been able to get Ranorex to run for that long).

With all that explained above, let me re0iterate that I cannot reliably reproduce this. Sometimes it will fail in finding a form at one location, the next iteration it runs fine and another form becomes the issue. There appears to be no rhyme or reason to it.

Thanks...
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...

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

Re: Help with reliability of searching for a form...

Post by Support Team » Tue Jul 28, 2009 11:10 am

That problem somehow reminds me of a bug already fixed in V2.1.0, where the communication to .NET controls broke and the control name can't be acquired from then on:
http://www.ranorex.com/forum/post2606.html
Which Ranorex version does this problem happen with? Are you using the latest Ranorex version (currently 2.1.2)?

Regards,
Alex
Ranorex Support Team

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

Re: Help with reliability of searching for a form...

Post by Ciege » Tue Jul 28, 2009 4:09 pm

This was running v 2.1.0.6243 of Ranorex.
It does sound similar to the issue that I had before that was fixed. That other issue was much more reproducible. This time, it will or won't happen at random times during my 4 hour test.
Adding the second try/catch to again check for the window has helped but is obviously not a solution.
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...

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

Re: Help with reliability of searching for a form...

Post by Support Team » Tue Jul 28, 2009 4:43 pm

Could you give me some more information, please:
- Does this happen only when you open a new form or create a new control? I.e. when you search for a control that is not there yet when you start the search?
- Is the CPU load high before the timeout is reached? I.e. is a search still in progress?
- Did you try setting the timeout to a "near infinite" value?

What I'm trying to find out is whether this is a bug in the Ranorex framework that causes a control not be found no matter how long the timeout is or if it is "just" a timing issue. 'cause I know how undeterministic the Windows task scheduler can be (we had a similar problem on one of our test VMWare machines where a Windows Forms application usually took 2 seconds to load, but sometimes - maybe when the host CPU was under pressure - needed up to a minute to get started).

Regards,
Alex
Ranorex Support Team

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

Re: Help with reliability of searching for a form...

Post by Ciege » Tue Jul 28, 2009 6:42 pm

I know this answer won't help at all, but here it is...

Since this complete test does take 4+ hours, sitting, watching and waiting is impractical. The times that I did see it happen the form was displayed but was never found by the Ranorex search.

The search method is called just after I try to invoke it through the AUT, be it with a pushbutton or menu item. So the search is probably starting just a second or less after it is invoked. Depending on speed of the AUT the form may take a few seconds to appear, so I would say more often than not, the search is started before the form actually exists.

I can't comment on the CPU load because I have not paid attention thus far, I will try to catch that if/when I can reproduce it.

I have not tried setting timeout to more than 60 seconds, but I am positive the times that it has failed, the form is already displayed and ready. That is partially the reason for the second search in the extra try/catch block... If the first search fails to find the form, the second usually does find it.

So all that being said, I do not believe it is a timing issue in that I am searching for my forms a minimum of 30 seconds on average and the times I did see this fail, the form was ready and waiting, but the search never found it.

Sorry I can't be more clear on the circumstances, it's another of those "quirky" issues that just can't be reliably reproduced.
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...

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

Re: Help with reliability of searching for a form...

Post by Support Team » Wed Jul 29, 2009 4:13 pm

Ciege wrote:I have not tried setting timeout to more than 60 seconds, but I am positive the times that it has failed, the form is already displayed and ready. That is partially the reason for the second search in the extra try/catch block... If the first search fails to find the form, the second usually does find it.
Actually, that's what makes me pretty sure that it's a timing issue, because two calls to FindSingle is equivalent to a single call to FindSingle with the summed timeout of the two calls.

In my opinion the problem is that you are searching all descendants of the ParentRanorexFormName element using the ".//form" RxPath syntax. That way you are searching all the descendants of the ParentRanorexFormName element and that can definitely take much time, especially if you are searching for a top-level form using this method, since then the whole element tree is searched for a form having that control name! If you know that the form you are searching for is a direct child of that ParentRanorexFormName element, you should use "./form" instead.

Could you just try to use a really high timeout (like an hour or so) to make me sure that's it not a timing issue? Thanks!

Regards,
Alex
Ranorex Support Team

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

Re: Help with reliability of searching for a form...

Post by Ciege » Wed Jul 29, 2009 5:53 pm

Understood. I will try the timing change and also see if my forms are direct children of the parent form or not and see if I can implement that change.

Thanks for the pointers and I'll let you know how that works out.
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...