From d7c672d1b76d890e200203d1e61db53e842247f5 Mon Sep 17 00:00:00 2001 From: Marcel Wagner Date: Wed, 31 Mar 2021 22:12:31 +0200 Subject: [PATCH] Add check for UIObject circles resulting in infinite loops (#3516) * Add check for UIObject circles resulting in infinite loops * Update check to break after encountering item 10 times in a row * Update logic --- .../MUXTestInfra/Common/FindElement.cs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/test/testinfra/MUXTestInfra/Common/FindElement.cs b/test/testinfra/MUXTestInfra/Common/FindElement.cs index a45dc173cd..3b8516ece9 100644 --- a/test/testinfra/MUXTestInfra/Common/FindElement.cs +++ b/test/testinfra/MUXTestInfra/Common/FindElement.cs @@ -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);