Try real retry

This commit is contained in:
Gleb Khmyznikov
2025-12-06 15:05:48 -08:00
parent 1c7ea7de2d
commit df5e9bb5ce
2 changed files with 67 additions and 30 deletions

View File

@@ -168,6 +168,12 @@ namespace Microsoft.PowerToys.UITest
}
private void TryLaunchPowerToysSettings(AppiumOptions opts)
{
const int maxTries = 3;
const int delayMs = 5000;
const int maxRetries = 2;
for (int tryCount = 1; tryCount <= maxTries; tryCount++)
{
try
{
@@ -181,15 +187,32 @@ namespace Microsoft.PowerToys.UITest
ExitExe(runnerProcessInfo.FileName);
runner = Process.Start(runnerProcessInfo);
WaitForWindowAndSetCapability(opts, "PowerToys Settings", 5000, 5);
if (WaitForWindowAndSetCapability(opts, "PowerToys Settings", delayMs, maxRetries))
{
// Exit CmdPal UI before launching new process if use installer for test
ExitExeByName("Microsoft.CmdPal.UI");
return;
}
// Window not found, kill all PowerToys processes and retry
if (tryCount < maxTries)
{
KillPowerToysProcesses();
}
}
catch (Exception ex)
{
throw new InvalidOperationException($"Failed to launch PowerToys Settings: {ex.Message}", ex);
if (tryCount == maxTries)
{
throw new InvalidOperationException($"Failed to launch PowerToys Settings after {maxTries} attempts: {ex.Message}", ex);
}
// Kill processes and retry
KillPowerToysProcesses();
}
}
throw new InvalidOperationException($"Failed to launch PowerToys Settings: Window not found after {maxTries} attempts.");
}
private void TryLaunchCommandPalette(AppiumOptions opts)
@@ -211,7 +234,10 @@ namespace Microsoft.PowerToys.UITest
var process = Process.Start(processStartInfo);
process?.WaitForExit();
WaitForWindowAndSetCapability(opts, "Command Palette", 5000, 10);
if (!WaitForWindowAndSetCapability(opts, "Command Palette", 5000, 10))
{
throw new TimeoutException("Failed to find Command Palette window after multiple attempts.");
}
}
catch (Exception ex)
{
@@ -219,7 +245,7 @@ namespace Microsoft.PowerToys.UITest
}
}
private void WaitForWindowAndSetCapability(AppiumOptions opts, string windowName, int delayMs, int maxRetries)
private bool WaitForWindowAndSetCapability(AppiumOptions opts, string windowName, int delayMs, int maxRetries)
{
for (int attempt = 1; attempt <= maxRetries; attempt++)
{
@@ -230,18 +256,16 @@ namespace Microsoft.PowerToys.UITest
{
var hexHwnd = window[0].HWnd.ToString("x");
opts.AddAdditionalCapability("appTopLevelWindow", hexHwnd);
return;
return true;
}
if (attempt < maxRetries)
{
Thread.Sleep(delayMs);
}
else
{
throw new TimeoutException($"Failed to find {windowName} window after multiple attempts.");
}
}
return false;
}
/// <summary>
@@ -327,5 +351,26 @@ namespace Microsoft.PowerToys.UITest
this.ExitExe(winAppDriverProcessInfo.FileName);
SessionHelper.appDriver = Process.Start(winAppDriverProcessInfo);
}
private void KillPowerToysProcesses()
{
var powerToysProcessNames = new[] { "PowerToys", "Microsoft.CmdPal.UI" };
foreach (var processName in powerToysProcessNames)
{
try
{
foreach (var process in Process.GetProcessesByName(processName))
{
process.Kill();
process.WaitForExit();
}
}
catch (Exception ex)
{
Debug.WriteLine($"Failed to kill process {processName}: {ex.Message}");
}
}
}
}
}

View File

@@ -53,14 +53,6 @@ namespace UITests_FancyZones
AppZoneHistory.DeleteFile();
FancyZonesEditorHelper.Files.Restore();
if (TestContext.TestName == "TestWarmup")
{
Thread.Sleep(5000);
Session.KillAllProcessesByName("PowerToys");
Thread.Sleep(5000);
return;
}
// Session.KillAllProcessesByName("PowerToys");
// Thread.Sleep(1000);
// ClearOpenWindows();