diff --git a/src/common/UITestAutomation/SessionHelper.cs b/src/common/UITestAutomation/SessionHelper.cs index 5832ac0cc8..d6c10bc70f 100644 --- a/src/common/UITestAutomation/SessionHelper.cs +++ b/src/common/UITestAutomation/SessionHelper.cs @@ -68,6 +68,7 @@ namespace Microsoft.PowerToys.UITest /// public void Cleanup() { + this.ExitScopeExe(); try { appDriver?.Kill(); @@ -80,6 +81,39 @@ namespace Microsoft.PowerToys.UITest } } + /// + /// Exit a exe. + /// + /// The path to the application executable. + public void ExitExe(string path) + { + // Exit Exe + string exeName = Path.GetFileNameWithoutExtension(path); + + // PowerToys.FancyZonesEditor + Process[] processes = Process.GetProcessesByName(exeName); + foreach (Process process in processes) + { + try + { + process.Kill(); + process.WaitForExit(); // Optional: Wait for the process to exit + } + catch (Exception ex) + { + Assert.Fail($"Failed to terminate process {process.ProcessName} (ID: {process.Id}): {ex.Message}"); + } + } + } + + /// + /// Exit now exe. + /// + public void ExitScopeExe() + { + this.ExitExe(sessionPath); + } + /// /// Starts a new exe and takes control of it. ///