diff --git a/src/common/UITestAutomation/FindHelper.cs b/src/common/UITestAutomation/FindHelper.cs index 38b3d3f1f9..db05d66229 100644 --- a/src/common/UITestAutomation/FindHelper.cs +++ b/src/common/UITestAutomation/FindHelper.cs @@ -19,19 +19,6 @@ namespace Microsoft.PowerToys.UITest { public static ReadOnlyCollection? FindAll(Func> findElementsFunc, WindowsDriver? driver, int timeoutMS) where T : Element, new() - { - var items = findElementsFunc(); - var res = items.Select(item => - { - var element = item as WindowsElement; - return NewElement(element, driver, timeoutMS); - }).Where(item => item.IsMatchingTarget()).ToList(); - - return new ReadOnlyCollection(res); - } - - public static ReadOnlyCollection? FindAll(Func> findElementsFunc, WindowsDriver? driver, int timeoutMS) - where T : Element, new() { var items = FindElementsWithRetry(findElementsFunc, timeoutMS); var res = items.Select(item => @@ -43,21 +30,21 @@ namespace Microsoft.PowerToys.UITest return new ReadOnlyCollection(res); } - private static ReadOnlyCollection FindElementsWithRetry(Func> findElementsFunc, int timeoutMS = 120000) + private static ReadOnlyCollection FindElementsWithRetry(Func> findElementsFunc, int timeoutMS) { - int retryIntervalMS = 500; - int elapsedTime = 0; + var timeout = TimeSpan.FromMilliseconds(timeoutMS); + var retryIntervalMS = TimeSpan.FromMilliseconds(500); + DateTime startTime = DateTime.Now; - while (elapsedTime < timeoutMS) + while (DateTime.Now - startTime < timeout) { var items = findElementsFunc(); if (items.Count > 0) { - return items; + return new ReadOnlyCollection((IList)items); } Task.Delay(retryIntervalMS).Wait(); - elapsedTime += retryIntervalMS; } return new ReadOnlyCollection(new List()); diff --git a/src/common/UITestAutomation/Session.cs b/src/common/UITestAutomation/Session.cs index 064c085f22..2ba4b44365 100644 --- a/src/common/UITestAutomation/Session.cs +++ b/src/common/UITestAutomation/Session.cs @@ -496,7 +496,7 @@ namespace Microsoft.PowerToys.UITest         break;     } -    Thread.Sleep(retryInterval); +    Task.Delay(retryInterval).Wait(); } if (matchingWindows == null || matchingWindows.Count == 0 || matchingWindows[0].HWnd == IntPtr.Zero) diff --git a/src/modules/Hosts/Hosts.UITests/HostModuleTests.cs b/src/modules/Hosts/Hosts.UITests/HostModuleTests.cs index beae5dc5c7..70cfe12746 100644 --- a/src/modules/Hosts/Hosts.UITests/HostModuleTests.cs +++ b/src/modules/Hosts/Hosts.UITests/HostModuleTests.cs @@ -283,25 +283,25 @@ namespace Hosts.UITests private void CloseWarningDialog() { // Find 'Accept' button which come in 'Warning' dialog - if (this.FindAll("Warning").Count > 0 && - this.FindAll