I've looked through available documentation, and can't seem to find the answer I'm looking for.
How would I go about waiting on a window to appear (say a main app window post-logon) with adequate timeout in case it never appeared?
Thanks in advance.
Waiting for window existence
Here was my solution:
Code: Select all
private static Ranorex.Form WaitForWindow(string WindowName, int Timeout)
{
/************************************************************************
* Function : WaitForWindow(string WindowName, int Timeout)
*
* Description : This function will wait for a window with a specific
* : Title to appear.
*
* Parameters : WindowName - Title of the window to wait for
* : 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
* ---------- : ------------------------- : ------------------------------
* 03/05/2009 : Chris Gendreau : Initial Creation
************************************************************************/
Ranorex.Form HDForm = null;
int error = -1;
bool boolFound = false;
int intCount = 0;
Report.Debug("Waiting for window: " + WindowName);
while (boolFound == false)
{
try
{
HDForm = Host.Local.FindChild<Ranorex.Form>(WindowName);
try
{
HDForm.Activate();
error = 0;
boolFound = true;
}
catch (RanorexException e)
{
error = -1;
boolFound = false;
}
}
catch (RanorexException e)
{
//Use DoEvents here so we don't get a ContextSwitchDeadlock error while debugging.
Application.DoEvents();
boolFound = false;
Thread.Sleep(1000);
intCount++;
if (intCount == Timeout) break;
error = -1;
}
}
if (boolFound == true)
{
HDForm.Activate();
}
Thread.Sleep(1000);
return HDForm;
} //End WaitForWindow
- Support Team
- Site Admin
- Posts: 12145
- Joined: Fri Jul 07, 2006 4:30 pm
- Location: Houston, Texas, USA
- Contact:
I suggest using something like this:
Michael
Ranorex Team
Code: Select all
try
{
// wait 10s for a window with title "My Main App"
Form myForm = Host.Local.FindSingle("/form[@title='My Main App']", 10000);
}
catch(ElementNotFoundException)
{
// your error handling code goes here
}
Ranorex Team
I'm new to Ranorex, and am still trying to get the lay of the land, so to speak.
I am working on a demo test in which I need to wait for a form to pop up. I see this code, but I'm not understanding where that's supposed to go if I'm not supposed to modify the code in the Recording1.cs file.
The Recording1.UserCode.cs only has the class initializer, but I'm guessing I can add a method with this "waiting code" in it, but how am I to call it if I'm not supposed to modify the code in the Recording1.cs file?
Thanks for your help,
Mike
I am working on a demo test in which I need to wait for a form to pop up. I see this code, but I'm not understanding where that's supposed to go if I'm not supposed to modify the code in the Recording1.cs file.
The Recording1.UserCode.cs only has the class initializer, but I'm guessing I can add a method with this "waiting code" in it, but how am I to call it if I'm not supposed to modify the code in the Recording1.cs file?
Thanks for your help,
Mike
- Support Team
- Site Admin
- Posts: 12145
- Joined: Fri Jul 07, 2006 4:30 pm
- Location: Houston, Texas, USA
- Contact: