/// <summary>
/// Only to be used if the Window is not guaranteed to appear.
/// </summary>
/// <param name="Condition"></param>
/// <param name="TimeOutInSeconds"></param>
/// <returns></returns>
public static bool CheckForWindow(IUIAutomationCondition Condition, double TimeOutInSeconds = 30)
{
bool found = false;
IUIAWindow windowToFind = null;
IUIAutomationOrCondition windowTypes = (IUIAutomationOrCondition)_autoclass.CreateOrConditionFromArray(new IUIAutomationCondition[]
{
_autoclass.CreatePropertyCondition(UIA_PropertyIds.UIA_LocalizedControlTypePropertyId, "dialog"),
_autoclass.CreatePropertyCondition(UIA_PropertyIds.UIA_LocalizedControlTypePropertyId, "window")
});
IUIAutomationAndCondition windowLocator = (IUIAutomationAndCondition)_autoclass.CreateAndConditionFromArray(new IUIAutomationCondition[]
{
_autoclass.CreatePropertyCondition(UIA_PropertyIds.UIA_ProcessIdPropertyId, BaseTest.ProcessID),
Condition,
windowTypes
});
DateTime dtStart = DateTime.Now;
DateTime dtCurrent;
for (int i = 0; i < 10000; i++)
{
new UIA_BaseScreen();
try
{
windowToFind = (IUIAWindow)_root.FindFirst(TreeScope.TreeScope_Descendants, windowLocator);
}
catch(COMException e) { }
dtCurrent = DateTime.Now;
if (windowToFind == null)
{
Console.WriteLine($"CheckForWindow Method - Window Not Yet Found!");
Thread.Sleep(250);
}
else
{
found = true;
Console.WriteLine($"CheckForWindow Method - Window Found!");
}
Console.WriteLine($"CheckForWindow Method - Iteration: [{i}] - Seconds Spent: [{(dtCurrent - dtStart).TotalSeconds}]");
if (found)
break;
if ((dtCurrent - dtStart).TotalSeconds > TimeOutInSeconds)
{
Console.WriteLine($"CheckForWindow Method - Did not locate window in Process ID [{BaseTest.ProcessID}] in the alotted time - Kicking out!");
return false;
}
}
return found;
}