Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add check for UIObject circles resulting in infinite loops #3516

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions test/testinfra/MUXTestInfra/Common/FindElement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -309,8 +309,25 @@ public static void Refresh()
Wait.ForIdle(findElementsIfNull: false); // false because otherwise Wait.ForIdle() might call Refresh(), and then we have an infinite loop.

UIObject window = TestEnvironment.Application.ApplicationFrameWindow ?? TestEnvironment.Application.CoreWindow;
int dupeCount = 0;
UIObject lastItem = null;
foreach (UIObject obj in window.Descendants)
{
// Check if we encounter the same element twice in a row indicating a loop in the UIObjects.
if(lastItem == obj)
{
dupeCount++;
}
else
{
dupeCount = 0;
lastItem = obj;
}
// Only break if an item was encountered more then 10 times.
if(dupeCount >= 10)
{
break;
}
if (!string.IsNullOrWhiteSpace(obj.AutomationId) && !objectFromIdCache.ContainsKey(obj.AutomationId))
{
objectFromIdCache.Add(obj.AutomationId, obj);
Expand Down