Skip to content

Commit

Permalink
Add check for UIObject circles resulting in infinite loops (#3516)
Browse files Browse the repository at this point in the history
* Add check for UIObject circles resulting in infinite loops

* Update check to break after encountering item 10 times in a row

* Update logic
  • Loading branch information
marcelwgn authored Mar 31, 2021
1 parent d5e6a00 commit d7c672d
Showing 1 changed file with 17 additions and 0 deletions.
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

0 comments on commit d7c672d

Please sign in to comment.