From ca473b488bc3df626140cd332b9a1ea4ff1fcdf2 Mon Sep 17 00:00:00 2001 From: Yu Leng <42196638+moooyo@users.noreply.github.com> Date: Fri, 18 Jul 2025 16:22:37 +0800 Subject: [PATCH] [CmdPal][UI Tests] Add basic test cases for cmdpal (#40694) ## Summary of the Pull Request 1. Create some basic cmdpal test cases. 2. Add ui tests support for cmdpal modules. ## PR Checklist - [x] **Closes:** #40695 - [x] **Communication:** I've discussed this with core contributors already. If the work hasn't been agreed, this work might be rejected - [x] **Tests:** Added/updated and all pass - [ ] **Localization:** All end-user-facing strings can be localized - [ ] **Dev docs:** Added/updated - [ ] **New binaries:** Added on the required places - [ ] [JSON for signing](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ESRPSigning_core.json) for new binaries - [ ] [WXS for installer](https://github.com/microsoft/PowerToys/blob/main/installer/PowerToysSetup/Product.wxs) for new binaries and localization folder - [ ] [YML for CI pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ci/templates/build-powertoys-steps.yml) for new test projects - [ ] [YML for signed pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/release.yml) - [ ] **Documentation updated:** If checked, please file a pull request on [our docs repo](https://github.com/MicrosoftDocs/windows-uwp/tree/docs/hub/powertoys) and link it here: #xxx ## Detailed Description of the Pull Request / Additional comments ## Validation Steps Performed --------- Co-authored-by: Yu Leng --- PowerToys.sln | 11 ++ .../UITestAutomation/ModuleConfigData.cs | 2 + .../Microsoft.CmdPal.UITests/BasicTests.cs | 151 ++++++++++++++++++ .../Microsoft.CmdPal.UITests.csproj | 26 +++ 4 files changed, 190 insertions(+) create mode 100644 src/modules/cmdpal/Microsoft.CmdPal.UITests/BasicTests.cs create mode 100644 src/modules/cmdpal/Microsoft.CmdPal.UITests/Microsoft.CmdPal.UITests.csproj diff --git a/PowerToys.sln b/PowerToys.sln index 6010ed421d..1ad9558e11 100644 --- a/PowerToys.sln +++ b/PowerToys.sln @@ -740,6 +740,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Core", "Core", "{02EA681E-C EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.CmdPal.Core.ViewModels", "src\modules\cmdpal\Microsoft.CmdPal.Core.ViewModels\Microsoft.CmdPal.Core.ViewModels.csproj", "{24133F7F-C1D1-DE04-EFA8-F5D5467FE027}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.CmdPal.UITests", "src\modules\cmdpal\Microsoft.CmdPal.UITests\Microsoft.CmdPal.UITests.csproj", "{840455DF-5634-51BB-D937-9D7D32F0B0C2}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|ARM64 = Debug|ARM64 @@ -2738,6 +2740,14 @@ Global {9D3F3793-EFE3-4525-8782-238015DABA62}.Release|ARM64.Build.0 = Release|ARM64 {9D3F3793-EFE3-4525-8782-238015DABA62}.Release|x64.ActiveCfg = Release|x64 {9D3F3793-EFE3-4525-8782-238015DABA62}.Release|x64.Build.0 = Release|x64 + {840455DF-5634-51BB-D937-9D7D32F0B0C2}.Debug|ARM64.ActiveCfg = Debug|ARM64 + {840455DF-5634-51BB-D937-9D7D32F0B0C2}.Debug|ARM64.Build.0 = Debug|ARM64 + {840455DF-5634-51BB-D937-9D7D32F0B0C2}.Debug|x64.ActiveCfg = Debug|x64 + {840455DF-5634-51BB-D937-9D7D32F0B0C2}.Debug|x64.Build.0 = Debug|x64 + {840455DF-5634-51BB-D937-9D7D32F0B0C2}.Release|ARM64.ActiveCfg = Release|ARM64 + {840455DF-5634-51BB-D937-9D7D32F0B0C2}.Release|ARM64.Build.0 = Release|ARM64 + {840455DF-5634-51BB-D937-9D7D32F0B0C2}.Release|x64.ActiveCfg = Release|x64 + {840455DF-5634-51BB-D937-9D7D32F0B0C2}.Release|x64.Build.0 = Release|x64 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -3025,6 +3035,7 @@ Global {02EA681E-C7D8-13C7-8484-4AC65E1B71E8} = {3846508C-77EB-4034-A702-F8BB263C4F79} {24133F7F-C1D1-DE04-EFA8-F5D5467FE027} = {02EA681E-C7D8-13C7-8484-4AC65E1B71E8} {9D3F3793-EFE3-4525-8782-238015DABA62} = {89E20BCE-EB9C-46C8-8B50-E01A82E6FDC3} + {840455DF-5634-51BB-D937-9D7D32F0B0C2} = {7520A2FE-00A2-49B8-83ED-DB216E874C04} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {C3A2F9D1-7930-4EF4-A6FC-7EE0A99821D0} diff --git a/src/common/UITestAutomation/ModuleConfigData.cs b/src/common/UITestAutomation/ModuleConfigData.cs index 56b8789251..456e893659 100644 --- a/src/common/UITestAutomation/ModuleConfigData.cs +++ b/src/common/UITestAutomation/ModuleConfigData.cs @@ -32,6 +32,7 @@ namespace Microsoft.PowerToys.UITest Runner, Workspaces, PowerRename, + CommandPalette, } /// @@ -104,6 +105,7 @@ namespace Microsoft.PowerToys.UITest [PowerToysModule.Runner] = new ModuleInfo("PowerToys.exe", "PowerToys"), [PowerToysModule.Workspaces] = new ModuleInfo("PowerToys.WorkspacesEditor.exe", "Workspaces Editor"), [PowerToysModule.PowerRename] = new ModuleInfo("PowerToys.PowerRename.exe", "PowerRename", "WinUI3Apps"), + [PowerToysModule.CommandPalette] = new ModuleInfo("Microsoft.CmdPal.UI.exe", "PowerToys Command Palette", "WinUI3Apps\\CmdPal"), }; } diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UITests/BasicTests.cs b/src/modules/cmdpal/Microsoft.CmdPal.UITests/BasicTests.cs new file mode 100644 index 0000000000..c1eea18d98 --- /dev/null +++ b/src/modules/cmdpal/Microsoft.CmdPal.UITests/BasicTests.cs @@ -0,0 +1,151 @@ +// Copyright (c) Microsoft Corporation +// The Microsoft Corporation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Threading.Tasks; +using Microsoft.PowerToys.UITest; +using Microsoft.VisualStudio.TestTools.UnitTesting; + +namespace Microsoft.CmdPal.UITests; + +[TestClass] +public class BasicTests : UITestBase +{ + public BasicTests() + : base(PowerToysModule.CommandPalette) + { + } + + private void SetSearchBox(string text) + { + Assert.AreEqual(this.Find("Type here to search...").SetText(text, true).Text, text); + } + + private void SetFilesExtensionSearchBox(string text) + { + Assert.AreEqual(this.Find("Search for files and folders...").SetText(text, true).Text, text); + } + + private void SetCalculatorExtensionSearchBox(string text) + { + Assert.AreEqual(this.Find("Type an equation...").SetText(text, true).Text, text); + } + + private void SetTimeAndDaterExtensionSearchBox(string text) + { + Assert.AreEqual(this.Find("Search values or type a custom time stamp...").SetText(text, true).Text, text); + } + + [TestMethod] + public void BasicFileSearchTest() + { + SetSearchBox("files"); + + var searchFileItem = this.Find("Search files"); + Assert.AreEqual(searchFileItem.Name, "Search files"); + searchFileItem.DoubleClick(); + + SetFilesExtensionSearchBox("AppData"); + + Assert.IsNotNull(this.Find("AppData")); + } + + [TestMethod] + public void BasicCalculatorTest() + { + SetSearchBox("calculator"); + + var searchFileItem = this.Find("Calculator"); + Assert.AreEqual(searchFileItem.Name, "Calculator"); + searchFileItem.DoubleClick(); + + SetCalculatorExtensionSearchBox("1+2"); + + Assert.IsNotNull(this.Find("3")); + } + + [TestMethod] + public void BasicTimeAndDateTest() + { + SetSearchBox("time and date"); + + var searchFileItem = this.Find("Time and Date"); + Assert.AreEqual(searchFileItem.Name, "Time and Date"); + searchFileItem.DoubleClick(); + + SetTimeAndDaterExtensionSearchBox("year"); + + Assert.IsNotNull(this.Find("2025")); + } + + [TestMethod] + public void BasicWindowsTerminalTest() + { + SetSearchBox("Windows Terminal"); + + var searchFileItem = this.Find("Open Windows Terminal Profiles"); + Assert.AreEqual(searchFileItem.Name, "Open Windows Terminal Profiles"); + searchFileItem.DoubleClick(); + + SetSearchBox("PowerShell"); + + Assert.IsNotNull(this.Find("PowerShell")); + } + + [TestMethod] + public void BasicWindowsSettingsTest() + { + SetSearchBox("Windows Settings"); + + var searchFileItem = this.Find("Windows Settings"); + Assert.AreEqual(searchFileItem.Name, "Windows Settings"); + searchFileItem.DoubleClick(); + + SetSearchBox("power"); + + Assert.IsNotNull(this.Find("Power and sleep")); + } + + [TestMethod] + public void BasicRegistryTest() + { + SetSearchBox("Registry"); + + var searchFileItem = this.Find("Registry"); + Assert.AreEqual(searchFileItem.Name, "Registry"); + searchFileItem.DoubleClick(); + + SetSearchBox("HKEY_LOCAL_MACHINE"); + + Assert.IsNotNull(this.Find("HKEY_LOCAL_MACHINE\\SECURITY")); + } + + [TestMethod] + public void BasicWindowsServicesTest() + { + SetSearchBox("Windows Services"); + + var searchFileItem = this.Find("Windows Services"); + Assert.AreEqual(searchFileItem.Name, "Windows Services"); + searchFileItem.DoubleClick(); + + SetSearchBox("hyper-v"); + + Assert.IsNotNull(this.Find("Hyper-V Heartbeat Service")); + } + + [TestMethod] + public void BasicWindowsSystemCommandsTest() + { + SetSearchBox("Windows System Commands"); + + var searchFileItem = this.Find("Windows System Commands"); + Assert.AreEqual(searchFileItem.Name, "Windows System Commands"); + searchFileItem.DoubleClick(); + + SetSearchBox("Sleep"); + + Assert.IsNotNull(this.Find("Sleep")); + } +} diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UITests/Microsoft.CmdPal.UITests.csproj b/src/modules/cmdpal/Microsoft.CmdPal.UITests/Microsoft.CmdPal.UITests.csproj new file mode 100644 index 0000000000..8518a381c8 --- /dev/null +++ b/src/modules/cmdpal/Microsoft.CmdPal.UITests/Microsoft.CmdPal.UITests.csproj @@ -0,0 +1,26 @@ + + + + + Microsoft.CmdPal.UITests + Microsoft.CmdPal.UITests + false + true + enable + Library + + false + + + + $(SolutionDir)$(Platform)\$(Configuration)\tests\Microsoft.CmdPal.UITests\ + + + + + + + + + + \ No newline at end of file