Skip to content

Commit

Permalink
UITestHelper: add TryFind overload with condition
Browse files Browse the repository at this point in the history
  • Loading branch information
jbe2277 committed Apr 30, 2024
1 parent 171c16a commit a8cb408
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/Samples.UITest/Writer.Test/UITestHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ public static class UITestHelper

public static AutomationElement? TryFind(this AutomationElement element, string automationId) => element.FindFirstDescendant(automationId);

public static AutomationElement? TryFind(this AutomationElement element, Func<ConditionFactory, ConditionBase> conditionFunc) => element.FindFirstDescendant(conditionFunc);

public static AutomationElement Find(this AutomationElement element, string automationId, TimeSpan? timeout = null)
{
var result = Retry.WhileNull(() => element.TryFind(automationId), timeout);
Expand All @@ -25,7 +27,7 @@ public static AutomationElement Find(this AutomationElement element, string auto

public static AutomationElement Find(this AutomationElement element, Func<ConditionFactory, ConditionBase> conditionFunc, TimeSpan? timeout = null)
{
var result = Retry.WhileNull(() => element.FindFirstDescendant(conditionFunc), timeout);
var result = Retry.WhileNull(() => element.TryFind(conditionFunc), timeout);
return result.Result ?? throw new ElementNotFoundException($"Element was not found as descendant of element '{element.TryAutomationId()}'"
+ Environment.NewLine + Environment.NewLine + element.GetTree());
}
Expand Down

0 comments on commit a8cb408

Please sign in to comment.