private static TControl StartSearchChild <TControl>(By by, From from, With with) where TControl : BasicElement { var condition = by.GetCondition(); var rawCondition = by.GetRawCondition(); var sourceElement = from.GetSourceElement(); var settings = with.GetConditions(); var useTimeout = settings.Contains(WithCondition.Timeout); var timeout = with.GetTimeout(); var assertResult = settings.Contains(WithCondition.Assert); var useInterval = settings.Contains(WithCondition.Interval); var interval = with.GetInterval(); var needsToBeReady = settings.Contains(WithCondition.ReadyToUse); if (CodedUIEnvironment.LoggerSettings.ShortLogging) { LogPool.Append("Search for UI element. {0}", by.GetConditionDescription()); } else { LogPool.Append("Search for UI element down from '{0}'. {1}", sourceElement, MessageBuilder.BuildMessage(by, useTimeout, useInterval, timeout, interval)); } var watch = new Stopwatch(); watch.Start(); while (true) { var foundItem = StartSearchChild <TControl>(sourceElement, condition, rawCondition); if (foundItem != null) { if (!needsToBeReady) { LogPool.Append("UI element '{0}' found.", foundItem); return(foundItem); } return(ReturnIfReady(assertResult, by, useTimeout, useInterval, timeout, watch, interval, false, foundItem)); } if (!useTimeout || watch.Elapsed.TotalMilliseconds >= timeout) { if (assertResult) { throw new UIElementNotFoundException(by, useTimeout, useInterval, interval, watch.Elapsed, false); } return(null); } if (useInterval) { Thread.Sleep((int)interval); } } }
private static IEnumerable <TControl> StartSearchChildren <TControl>(By by, From from, With with) where TControl : BasicElement { var condition = by.GetCondition(); var rawCondition = by.GetRawCondition(); var sourceElement = from.GetSourceElement(); var settings = with.GetConditions(); var useTimeout = settings.Contains(WithCondition.Timeout); var timeout = with.GetTimeout(); var assertResult = settings.Contains(WithCondition.Assert); var useInterval = settings.Contains(WithCondition.Interval); var interval = with.GetInterval(); var needsToBeReady = settings.Contains(WithCondition.ReadyToUse); if (CodedUIEnvironment.LoggerSettings.ShortLogging) { LogPool.Append("Search for UI elements. {0}", by.GetConditionDescription()); } else { LogPool.Append("Search for UI elements down from '{0}'. {1}", sourceElement, MessageBuilder.BuildMessage(by, useTimeout, useInterval, timeout, interval)); } var foundItems = new List <TControl>(); var watch = new Stopwatch(); watch.Start(); while (true) { foundItems.AddRange(StartSearchChildren <TControl>(sourceElement, condition, rawCondition)); if (foundItems.Any()) { if (!needsToBeReady) { LogPool.Append("{0} element(s) found.", foundItems.Count); return(foundItems); } for (var i = 0; i < foundItems.Count; ++i) { var foundItem = foundItems[i]; var readyElement = ReturnIfReady(assertResult, by, useTimeout, useInterval, timeout, watch, interval, true, foundItem); if (readyElement == null) { foundItems.RemoveAt(i); --i; } } } if (!useTimeout || watch.Elapsed.TotalMilliseconds >= timeout) { if (assertResult) { throw new UIElementNotFoundException(by, useTimeout, useInterval, interval, watch.Elapsed, true); } return(foundItems); } if (useInterval) { Thread.Sleep((int)interval); } } }