Files
PowerToys/src/settings-ui/UITest-Settings/OOBEUITests.cs

237 lines
7.5 KiB
C#
Raw Normal View History

[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
// 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}");
}
}
}
}