Files
PowerToys/src/settings-ui/UITest-Settings/SettingsTests.cs
Shawn Yuan 37c80b40bf [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>
2025-07-23 17:18:04 +08:00

150 lines
4.4 KiB
C#

// 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;
}
}
}