From e2b2520665851cf66149bfdc2f7a1e4e803e73ed Mon Sep 17 00:00:00 2001 From: Leilei Zhang Date: Tue, 8 Jul 2025 20:57:57 +0800 Subject: [PATCH] update test --- .pipelines/v2/templates/job-test-project.yml | 7 ++- .../pipeline-ui-tests-automation.yml | 3 + .../UITestAutomation/ModuleConfigData.cs | 57 ++++++++++++++++++- 3 files changed, 65 insertions(+), 2 deletions(-) diff --git a/.pipelines/v2/templates/job-test-project.yml b/.pipelines/v2/templates/job-test-project.yml index b206b1a422..132de413d4 100644 --- a/.pipelines/v2/templates/job-test-project.yml +++ b/.pipelines/v2/templates/job-test-project.yml @@ -11,6 +11,9 @@ parameters: - name: useLatestWebView2 type: boolean default: false + - name: useLatestOfficialBuild + type: boolean + default: true jobs: - job: Test${{ parameters.platform }}${{ parameters.configuration }} @@ -102,10 +105,11 @@ jobs: definition: '76541' buildVersionToDownload: 'latest' branchName: 'refs/heads/main' - artifactName: 'build-${{ parameters.platform }}-Release' + artifactName: 'build-$(BuildPlatform)-Release' targetPath: '$(Build.ArtifactStagingDirectory)' patterns: | **/PowerToysSetup-*.exe + - pwsh: |- & "$(build.sourcesdirectory)\.pipelines\installPowerToys.ps1" displayName: Install PowerToys @@ -125,6 +129,7 @@ jobs: vsTestVersion: 'toolsInstaller' uiTests: true rerunFailedTests: true + useInstallerForTest: ${{ parameters.useLatestOfficialBuild }} # Since UITests-FancyZonesEditor.dll is generated in both UITests-FancyZonesEditor and UITests-FancyZones, removed one to avoid duplicate test runs testAssemblyVer2: | **\*UITest*.dll diff --git a/.pipelines/v2/templates/pipeline-ui-tests-automation.yml b/.pipelines/v2/templates/pipeline-ui-tests-automation.yml index 1bed6c3d3e..0504ed1191 100644 --- a/.pipelines/v2/templates/pipeline-ui-tests-automation.yml +++ b/.pipelines/v2/templates/pipeline-ui-tests-automation.yml @@ -83,6 +83,7 @@ stages: platform: x64Win10 configuration: Release useLatestWebView2: ${{ parameters.useLatestWebView2 }} + useLatestOfficialBuild: ${{ parameters.useLatestOfficialBuild }} - ${{ if eq(platform, 'x64') }}: - stage: Test_x64Win11 @@ -99,6 +100,7 @@ stages: platform: x64Win11 configuration: Release useLatestWebView2: ${{ parameters.useLatestWebView2 }} + useLatestOfficialBuild: ${{ parameters.useLatestOfficialBuild }} - ${{ if ne(platform, 'x64') }}: - stage: Test_${{ platform }} @@ -115,3 +117,4 @@ stages: platform: ${{ platform }} configuration: Release useLatestWebView2: ${{ parameters.useLatestWebView2 }} + useLatestOfficialBuild: ${{ parameters.useLatestOfficialBuild }} diff --git a/src/common/UITestAutomation/ModuleConfigData.cs b/src/common/UITestAutomation/ModuleConfigData.cs index 3572ce5331..c90c036154 100644 --- a/src/common/UITestAutomation/ModuleConfigData.cs +++ b/src/common/UITestAutomation/ModuleConfigData.cs @@ -89,6 +89,11 @@ namespace Microsoft.PowerToys.UITest private ModuleConfigData() { + // Check if we should use installer paths from environment variable + string useInstallerForTestEnv = Environment.GetEnvironmentVariable("useInstallerForTest") ?? + Environment.GetEnvironmentVariable("USEINSTALLERFORTEST"); + UseInstallerForTest = bool.TryParse(useInstallerForTestEnv, out bool result) && result; + // The exe window name for each module. ModuleWindowName = new Dictionary { @@ -108,9 +113,59 @@ namespace Microsoft.PowerToys.UITest [PowerToysModule.Runner] = @"\..\..\..\PowerToys.exe", [PowerToysModule.Workspaces] = @"\..\..\..\PowerToys.WorkspacesEditor.exe", }; + + // Installed PowerToys paths + string powerToysInstallPath = GetPowerToysInstallPath(); + InstalledModulePath = new Dictionary + { + [PowerToysModule.PowerToysSettings] = Path.Combine(powerToysInstallPath, "WinUI3Apps", "PowerToys.Settings.exe"), + [PowerToysModule.FancyZone] = Path.Combine(powerToysInstallPath, "PowerToys.FancyZonesEditor.exe"), + [PowerToysModule.Hosts] = Path.Combine(powerToysInstallPath, "WinUI3Apps", "PowerToys.Hosts.exe"), + [PowerToysModule.Runner] = Path.Combine(powerToysInstallPath, "PowerToys.exe"), + [PowerToysModule.Workspaces] = Path.Combine(powerToysInstallPath, "PowerToys.WorkspacesEditor.exe"), + }; } - public string GetModulePath(PowerToysModule scope) => ModulePath[scope]; + private string GetPowerToysInstallPath() + { + // Try common installation paths + string[] possiblePaths = { + @"C:\Program Files\PowerToys", + @"C:\Program Files (x86)\PowerToys", + Environment.ExpandEnvironmentVariables(@"%LocalAppData%\Microsoft\PowerToys"), + Environment.ExpandEnvironmentVariables(@"%ProgramFiles%\PowerToys") + }; + + foreach (string path in possiblePaths) + { + if (Directory.Exists(path) && File.Exists(Path.Combine(path, "PowerToys.exe"))) + { + return path; + } + } + + // Fallback to Program Files if not found + return @"C:\Program Files\PowerToys"; + } + + public string GetModulePath(PowerToysModule scope) + { + if (UseInstallerForTest) + { + string installedPath = InstalledModulePath[scope]; + if (File.Exists(installedPath)) + { + return installedPath; + } + else + { + // Log warning and fallback to development path + Console.WriteLine($"Warning: Installed module not found at {installedPath}, using development path"); + } + } + + return ModulePath[scope]; + } public string GetWindowsApplicationDriverUrl() => WindowsApplicationDriverUrl;