Help with reliability of searching for a form...
Posted: 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:
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!
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
Can you offer any suggestions as to how to increase the reliability of this method?
Thanks!