[UITest] Added UITest for advancedPaste (#40745)

<!-- Enter a brief description/summary of your PR here. What does it
fix/what does it change/how was it tested (even manually, if necessary)?
-->
## Summary of the Pull Request
Added UITest for advancedPaste
Also add test init code for color picker and settings.
<!-- Please review the items on the PR checklist before submitting-->
## PR Checklist

- [ ] **Closes:** #xxx
- [ ] **Communication:** I've discussed this with core contributors
already. If the work hasn't been agreed, this work might be rejected
- [ ] **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

<!-- Provide a more detailed description of the PR, other things fixed,
or any additional comments/features here -->
## Detailed Description of the Pull Request / Additional comments

<!-- Describe how you validated the behavior. Add automated tests
wherever possible, but list manual validation steps taken as well -->
## Validation Steps Performed

---------

Signed-off-by: Shawn Yuan <shuaiyuan@microsoft.com>
This commit is contained in:
Shawn Yuan
2025-07-23 17:18:04 +08:00
committed by GitHub
parent a0fd2d1517
commit 37c80b40bf
24 changed files with 1616 additions and 15 deletions

View File

@@ -0,0 +1,236 @@
// 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.Diagnostics;
using System.IO;
using System.Reflection;
using System.Threading.Tasks;
using Microsoft.PowerToys.UITest;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace Microsoft.Settings.UITests
{
[TestClass]
public class OOBEUITests : UITestBase
{
// Constants for file paths and identifiers
private const string LocalAppDataFolderPath = "%localappdata%\\Microsoft\\PowerToys";
private const string LastVersionFilePath = "%localappdata%\\Microsoft\\PowerToys\\last_version.txt";
public OOBEUITests()
: base(PowerToysModule.PowerToysSettings)
{
}
[TestMethod("OOBE.Basic.FirstStartTest")]
[TestCategory("OOBE test #1")]
public void TestOOBEFirstStart()
{
// Clean up previous PowerToys data to simulate first start
// CleanPowerToysData();
// Start PowerToys and verify OOBE opens
// StartPowerToysAndVerifyOOBEOpens();
// Navigate through all OOBE sections
NavigateThroughOOBESections();
// Close OOBE
CloseOOBE();
// Verify OOBE can be opened from Settings
// OpenOOBEFromSettings();
}
/*
[TestMethod("OOBE.WhatsNew.Test")]
[TestCategory("OOBE test #2")]
public void TestOOBEWhatsNew()
{
// Modify version file to trigger What's New
ModifyLastVersionFile();
// Start PowerToys and verify OOBE opens in What's New page
StartPowerToysAndVerifyWhatsNewOpens();
// Close OOBE
CloseOOBE();
}
*/
private void CleanPowerToysData()
{
this.ExitScopeExe();
// Exit PowerToys if it's running
try
{
foreach (Process process in Process.GetProcessesByName("PowerToys"))
{
process.Kill();
process.WaitForExit();
}
// Delete PowerToys folder in LocalAppData
string powerToysFolder = Environment.ExpandEnvironmentVariables(LocalAppDataFolderPath);
if (Directory.Exists(powerToysFolder))
{
Directory.Delete(powerToysFolder, true);
}
// Wait to ensure deletion is complete
Task.Delay(1000).Wait();
}
catch (Exception ex)
{
Assert.Inconclusive($"Could not clean PowerToys data: {ex.Message}");
}
}
private void StartPowerToysAndVerifyOOBEOpens()
{
try
{
// Start PowerToys
this.RestartScopeExe();
// Wait for OOBE window to appear
Task.Delay(5000).Wait();
// Verify OOBE window opened
Assert.IsTrue(this.Session.HasOne("Welcome to PowerToys"), "OOBE window should open with 'Welcome to PowerToys' title");
// Verify we're on the Overview page
Assert.IsTrue(this.Has("Overview"), "OOBE should start on Overview page");
}
catch (Exception ex)
{
Assert.Fail($"Failed to start PowerToys and verify OOBE: {ex.Message}");
}
}
private void NavigateThroughOOBESections()
{
// List of modules to test
string[] modules = new string[]
{
"What's new",
"Advanced Paste",
};
this.Find<NavigationViewItem>("Welcome to PowerToys").Click();
foreach (string module in modules)
{
TestModule(module);
}
}
private void TestModule(string moduleName)
{
var oobeWindow = this.Find<Window>("Welcome to PowerToys");
Assert.IsNotNull(oobeWindow);
/*
- [] open the Settings for that module
- [] verify the Settings work as expected (toggle some controls on/off etc.)
- [] close the Settings
- [] if it's available, test the `Launch module name` button
*/
oobeWindow.Find<Button>(By.Name("Open Settings")).Click();
// Find<NavigationViewItem>("What's new").Click();
Task.Delay(1000).Wait();
}
private void CloseOOBE()
{
try
{
// Find the close button and click it
this.Session.CloseMainWindow();
Task.Delay(1000).Wait();
}
catch (Exception ex)
{
Assert.Fail($"Failed to close OOBE: {ex.Message}");
}
}
private void OpenOOBEFromSettings()
{
try
{
// Open PowerToys Settings
this.Session.Attach(PowerToysModule.PowerToysSettings);
// Navigate to General page
this.Find<NavigationViewItem>("General").Click();
Task.Delay(1000).Wait();
// Click on "Welcome to PowerToys" link
this.Find<HyperlinkButton>("Welcome to PowerToys").Click();
Task.Delay(2000).Wait();
// Verify OOBE opened
Assert.IsTrue(this.Session.HasOne("Welcome to PowerToys"), "OOBE should open when clicking the link in Settings");
// Close OOBE
this.Session.CloseMainWindow();
}
catch (Exception ex)
{
Assert.Fail($"Failed to open OOBE from Settings: {ex.Message}");
}
}
private void ModifyLastVersionFile()
{
try
{
// Create PowerToys folder if it doesn't exist
string powerToysFolder = Environment.ExpandEnvironmentVariables(LocalAppDataFolderPath);
if (!Directory.Exists(powerToysFolder))
{
Directory.CreateDirectory(powerToysFolder);
}
// Write a different version to trigger What's New
string versionFilePath = Environment.ExpandEnvironmentVariables(LastVersionFilePath);
File.WriteAllText(versionFilePath, "0.0.1");
// Wait to ensure file is written
Task.Delay(1000).Wait();
}
catch (Exception ex)
{
Assert.Inconclusive($"Could not modify version file: {ex.Message}");
}
}
private void StartPowerToysAndVerifyWhatsNewOpens()
{
try
{
// Start PowerToys
this.RestartScopeExe();
// Wait for OOBE window to appear
Task.Delay(5000).Wait();
// Verify OOBE window opened
Assert.IsTrue(this.Session.HasOne("Welcome to PowerToys"), "OOBE window should open");
// Verify we're on the What's New page
Assert.IsTrue(this.Has("What's new"), "OOBE should open on What's New page after version change");
}
catch (Exception ex)
{
Assert.Fail($"Failed to verify What's New page: {ex.Message}");
}
}
}
}

View File

@@ -0,0 +1,149 @@
// 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.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;
using Microsoft.PowerToys.UITest;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Windows.Devices.PointOfService.Provider;
namespace Microsoft.Settings.UITests
{
[TestClass]
public class SettingsTests : UITestBase
{
private readonly string[] dashboardModuleList =
{
"Advanced Paste",
"Always On Top",
"Awake",
"Color Picker",
"Command Palette",
"Environment Variables",
"FancyZones",
"File Locksmith",
"Find My Mouse",
"Hosts File Editor",
"Image Resizer",
"Keyboard Manager",
"Mouse Highlighter",
"Mouse Jump",
"Mouse Pointer Crosshairs",
"Mouse Without Borders",
"New+",
"Peek",
"PowerRename",
"PowerToys Run",
"Quick Accent",
"Registry Preview",
"Screen Ruler",
"Shortcut Guide",
"Text Extractor",
"Workspaces",
"ZoomIt",
// "Crop And Lock", // this module cannot be found, why?
};
private readonly string[] moduleProcess =
{
"PowerToys.AdvancedPaste",
"PowerToys.Run",
"PowerToys.AlwaysOnTop",
"PowerToys.Awake",
"PowerToys.ColorPickerUI",
"PowerToys.Peek.UI",
};
public SettingsTests()
: base(PowerToysModule.PowerToysSettings, size: WindowSize.Large)
{
}
[TestMethod("PowerToys.Settings.ModulesOnAndOffTest")]
[TestCategory("Settings Test #1")]
public void TestAllmoduleOnAndOff()
{
DisableAllModules();
Task.Delay(2000).Wait();
// module process won't be killed in debug mode settings UI!
// Assert.IsTrue(CheckModulesDisabled(), "Some modules are not disabled.");
EnableAllModules();
Task.Delay(2000).Wait();
// Assert.IsTrue(CheckModulesEnabled(), "Some modules are not Enabled.");
}
private void DisableAllModules()
{
Find<NavigationViewItem>("Dashboard").Click();
foreach (var moduleName in dashboardModuleList)
{
var moduleButton = Find<Button>(moduleName);
Assert.IsNotNull(moduleButton);
var toggle = moduleButton.Find<ToggleSwitch>("Enable module");
Assert.IsNotNull(toggle);
if (toggle.IsOn)
{
toggle.Click();
}
}
}
private void EnableAllModules()
{
Find<NavigationViewItem>("Dashboard").Click();
foreach (var moduleName in dashboardModuleList)
{
// Scroll(direction: "Down");
var moduleButton = Find<Button>(moduleName);
Assert.IsNotNull(moduleButton);
var toggle = moduleButton.Find<ToggleSwitch>("Enable module");
Assert.IsNotNull(toggle);
if (!toggle.IsOn)
{
toggle.Click();
}
}
}
private bool CheckModulesDisabled()
{
Process[] runningProcesses = Process.GetProcesses();
foreach (var process in moduleProcess)
{
if (runningProcesses.Any(p => p.ProcessName.Equals(process, StringComparison.OrdinalIgnoreCase)))
{
return false;
}
}
return true;
}
private bool CheckModulesEnabled()
{
Process[] runningProcesses = Process.GetProcesses();
foreach (var process in moduleProcess)
{
if (!runningProcesses.Any(p => p.ProcessName.Equals(process, StringComparison.OrdinalIgnoreCase)))
{
return false;
}
}
return true;
}
}
}

View File

@@ -0,0 +1,41 @@
## [General Settings](tests-checklist-template-settings-section.md)
**Admin mode:**
- [] restart PT and verify it runs as user
- [] restart as admin and set "Always run as admin"
- [] restart PT and verify it runs as admin
* if it's not on, turn on "Run at startup"
- [] reboot the machine and verify PT runs as admin (it should not prompt the UAC dialog)
* turn Always run as admin" off
- [] reboot the machine and verify it now runs as user
**Modules on/off:**
- [x] turn off all the modules and verify all module are off
- [] restart PT and verify that all module are still off in the settings page and they are actually inactive
- [x] turn on all the module, all module are now working
- [] restart PT and verify that all module are still on in the settings page and they are actually working
**Quick access tray icon flyout:**
- [] Use left click on the system tray icon and verify the flyout appears.
- [] Try to launch a module from the launch screen in the flyout.
- [] Try disabling a module in the all apps screen in the flyout, make it a module that's launchable from the launch screen. Verify that the module is disabled and that it also disappeared from the launch screen in the flyout.
- [] Open the main settings screen on a module page. Verify that when you disable/enable the module on the flyout, that the Settings page is updated too.
**Settings backup/restore:**
- [] In the General tab, create a backup of the settings.
- [] Change some settings in some PowerToys.
- [] Restore the settings in the General tab and verify the Settings you've applied were reset.
## OOBE
* Quit PowerToys
* Delete %localappdata%\Microsoft\PowerToys
- [] Start PowerToys and verify OOBE opens
* Change version saved on `%localappdata%\Microsoft\PowerToys\last_version.txt`
- [] Start PowerToys and verify OOBE opens in the "What's New" page
* Visit each OOBE section and for each section:
- [] open the Settings for that module
- [] verify the Settings work as expected (toggle some controls on/off etc.)
- [] close the Settings
- [] if it's available, test the `Launch module name` button
* Close OOBE
- [x] Open the Settings and from the General page open OOBE using the `Welcome to PowerToys` link

View File

@@ -0,0 +1,32 @@
<Project Sdk="Microsoft.NET.Sdk">
<!-- Look at Directory.Build.props in root for common stuff as well -->
<Import Project="..\..\Common.Dotnet.CsWinRT.props" />
<PropertyGroup>
<ProjectGuid>{29B91A80-0590-4B1F-89B8-4F8812A7F116}</ProjectGuid>
<RootNamespace>Microsoft.Settings.UITests</RootNamespace>
<IsPackable>false</IsPackable>
<Nullable>enable</Nullable>
<OutputType>Library</OutputType>
<!-- This is a UI test, so don't run as part of MSBuild -->
<RunVSTest>false</RunVSTest>
</PropertyGroup>
<PropertyGroup>
<OutputPath>..\..\..\$(Platform)\$(Configuration)\tests\UITests-Settings\</OutputPath>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Appium.WebDriver" />
<PackageReference Include="MSTest" />
<PackageReference Include="System.Net.Http" />
<PackageReference Include="System.Private.Uri" />
<PackageReference Include="System.Text.RegularExpressions" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\common\UITestAutomation\UITestAutomation.csproj" />
</ItemGroup>
</Project>