[UI tests] Add accessibility IDs to settings navigation items and fix part of FancyZones issues (#41458)

<!-- 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
This pull request adds automation-friendly identifiers to navigation and
toggle UI elements throughout the PowerToys Settings. The main goal is
to improve UI test reliability and maintainability by using stable
`AutomationId` and `x:Name` attributes instead of relying on visible
text. It also updates the UI tests to use these new identifiers.

These changes make the UI automation more robust against localization
and UI text changes, improving test reliability and maintainability.
<!-- 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
This commit is contained in:
leileizhang
2025-08-29 15:08:44 +08:00
committed by GitHub
parent eb35b3a249
commit 3882db4479
3 changed files with 89 additions and 10 deletions

View File

@@ -372,20 +372,17 @@ namespace UITests_FancyZones
// launch FancyZones settings page
private void LaunchFancyZones()
{
if (this.FindAll<NavigationViewItem>("FancyZones").Count == 0)
{
this.Find<NavigationViewItem>("Windowing & Layouts").Click();
}
this.Find<NavigationViewItem>(By.AccessibilityId("WindowingAndLayoutsNavItem")).Click();
this.Find<NavigationViewItem>("FancyZones").Click();
this.Find<ToggleSwitch>("Enable FancyZones").Toggle(true);
this.Find<NavigationViewItem>(By.AccessibilityId("FancyZonesNavItem")).Click();
this.Find<ToggleSwitch>(By.AccessibilityId("EnableFancyZonesToggleSwitch")).Toggle(true);
this.Session.SetMainWindowSize(WindowSize.Large);
Find<Element>(By.AccessibilityId("HeaderPresenter")).Click();
this.Scroll(6, "Down"); // Pull the settings page up to make sure the settings are visible
ZoneBehaviourSettings(TestContext.TestName);
this.Find<Microsoft.PowerToys.UITest.Button>("Launch layout editor").Click(false, 500, 10000);
this.Find<Microsoft.PowerToys.UITest.Button>(By.AccessibilityId("LaunchLayoutEditorButton")).Click(false, 500, 10000);
this.Session.Attach(PowerToysModule.FancyZone);
// pipeline machine may have an unstable delays, causing the custom layout to be unavailable as we set. then A retry is required.
@@ -403,7 +400,7 @@ namespace UITests_FancyZones
this.Find<Microsoft.PowerToys.UITest.Button>("Close").Click();
this.Session.Attach(PowerToysModule.PowerToysSettings);
SetupCustomLayouts();
this.Find<Microsoft.PowerToys.UITest.Button>("Launch layout editor").Click(false, 5000, 5000);
this.Find<Microsoft.PowerToys.UITest.Button>(By.AccessibilityId("LaunchLayoutEditorButton")).Click(false, 5000, 5000);
this.Session.Attach(PowerToysModule.FancyZone);
this.Find<Microsoft.PowerToys.UITest.Button>("Maximize").Click();

View File

@@ -19,7 +19,11 @@
x:Uid="FancyZones_EnableToggleControl_HeaderText"
HeaderIcon="{ui:BitmapIcon Source=/Assets/Settings/Icons/FancyZones.png}"
IsEnabled="{x:Bind ViewModel.IsEnabledGpoConfigured, Mode=OneWay, Converter={StaticResource BoolNegationConverter}}">
<ToggleSwitch x:Uid="ToggleSwitch" IsOn="{x:Bind ViewModel.IsEnabled, Mode=TwoWay}" />
<ToggleSwitch
x:Name="EnableFancyZonesToggleSwitch"
x:Uid="ToggleSwitch"
AutomationProperties.AutomationId="EnableFancyZonesToggleSwitch"
IsOn="{x:Bind ViewModel.IsEnabled, Mode=TwoWay}" />
</tkcontrols:SettingsCard>
<InfoBar
x:Uid="GPO_SettingIsManaged"

View File

@@ -146,11 +146,17 @@
</NavigationView.Resources>
<NavigationView.MenuItems>
<NavigationViewItem
x:Name="DashboardNavigationItem"
x:Uid="Shell_Dashboard"
helpers:NavHelper.NavigateTo="views:DashboardPage"
AutomationProperties.AutomationId="DashboardNavItem"
Icon="{ui:FontIcon Glyph=&#xE80F;}" />
<NavigationViewItem x:Uid="Shell_General" helpers:NavHelper.NavigateTo="views:GeneralPage">
<NavigationViewItem
x:Name="GeneralNavigationItem"
x:Uid="Shell_General"
helpers:NavHelper.NavigateTo="views:GeneralPage"
AutomationProperties.AutomationId="GeneralNavItem">
<NavigationViewItem.Icon>
<AnimatedIcon>
<AnimatedIcon.Source>
@@ -166,156 +172,220 @@
<!-- System Tools -->
<NavigationViewItem
x:Name="SystemToolsNavigationItem"
x:Uid="Shell_TopLevelSystemTools"
AutomationProperties.AutomationId="SystemToolsNavItem"
Icon="{ui:BitmapIcon Source=/Assets/Settings/Icons/SystemTools.png}"
SelectsOnInvoked="False">
<NavigationViewItem.MenuItems>
<NavigationViewItem
x:Name="AdvancedPasteNavigationItem"
x:Uid="Shell_AdvancedPaste"
helpers:NavHelper.NavigateTo="views:AdvancedPastePage"
AutomationProperties.AutomationId="AdvancedPasteNavItem"
Icon="{ui:BitmapIcon Source=/Assets/Settings/Icons/AdvancedPaste.png}" />
<NavigationViewItem
x:Name="AwakeNavigationItem"
x:Uid="Shell_Awake"
helpers:NavHelper.NavigateTo="views:AwakePage"
AutomationProperties.AutomationId="AwakeNavItem"
Icon="{ui:BitmapIcon Source=/Assets/Settings/Icons/Awake.png}" />
<NavigationViewItem
x:Name="CmdPalNavigationItem"
x:Uid="Shell_CmdPal"
helpers:NavHelper.NavigateTo="views:CmdPalPage"
AutomationProperties.AutomationId="CmdPalNavItem"
Icon="{ui:BitmapIcon Source=/Assets/Settings/Icons/CmdPal.png}" />
<NavigationViewItem
x:Name="ColorPickerNavigationItem"
x:Uid="Shell_ColorPicker"
helpers:NavHelper.NavigateTo="views:ColorPickerPage"
AutomationProperties.AutomationId="ColorPickerNavItem"
Icon="{ui:BitmapIcon Source=/Assets/Settings/Icons/ColorPicker.png}" />
<NavigationViewItem
x:Name="PowerLauncherNavigationItem"
x:Uid="Shell_PowerLauncher"
helpers:NavHelper.NavigateTo="views:PowerLauncherPage"
AutomationProperties.AutomationId="PowerLauncherNavItem"
Icon="{ui:BitmapIcon Source=/Assets/Settings/Icons/PowerToysRun.png}" />
<NavigationViewItem
x:Name="MeasureToolNavigationItem"
x:Uid="Shell_MeasureTool"
helpers:NavHelper.NavigateTo="views:MeasureToolPage"
AutomationProperties.AutomationId="MeasureToolNavItem"
Icon="{ui:BitmapIcon Source=/Assets/Settings/Icons/ScreenRuler.png}" />
<NavigationViewItem
x:Name="ShortcutGuideNavigationItem"
x:Uid="Shell_ShortcutGuide"
helpers:NavHelper.NavigateTo="views:ShortcutGuidePage"
AutomationProperties.AutomationId="ShortcutGuideNavItem"
Icon="{ui:BitmapIcon Source=/Assets/Settings/Icons/ShortcutGuide.png}" />
<NavigationViewItem
x:Name="TextExtractorNavigationItem"
x:Uid="Shell_TextExtractor"
helpers:NavHelper.NavigateTo="views:PowerOcrPage"
AutomationProperties.AutomationId="TextExtractorNavItem"
Icon="{ui:BitmapIcon Source=/Assets/Settings/Icons/TextExtractor.png}" />
<NavigationViewItem
x:Name="ZoomItNavigationItem"
x:Uid="Shell_ZoomIt"
helpers:NavHelper.NavigateTo="views:ZoomItPage"
AutomationProperties.AutomationId="ZoomItNavItem"
Icon="{ui:BitmapIcon Source=/Assets/Settings/Icons/ZoomIt.png}" />
</NavigationViewItem.MenuItems>
</NavigationViewItem>
<!-- Windowing & Layouts -->
<NavigationViewItem
x:Name="WindowingAndLayoutsNavigationItem"
x:Uid="Shell_TopLevelWindowsAndLayouts "
AutomationProperties.AutomationId="WindowingAndLayoutsNavItem"
Icon="{ui:BitmapIcon Source=/Assets/Settings/Icons/WindowingAndLayouts.png}"
SelectsOnInvoked="False">
<NavigationViewItem.MenuItems>
<NavigationViewItem
x:Name="AlwaysOnTopNavigationItem"
x:Uid="Shell_AlwaysOnTop"
helpers:NavHelper.NavigateTo="views:AlwaysOnTopPage"
AutomationProperties.AutomationId="AlwaysOnTopNavItem"
Icon="{ui:BitmapIcon Source=/Assets/Settings/Icons/AlwaysOnTop.png}" />
<NavigationViewItem
x:Name="CropAndLockNavigationItem"
x:Uid="Shell_CropAndLock"
helpers:NavHelper.NavigateTo="views:CropAndLockPage"
AutomationProperties.AutomationId="CropAndLockNavItem"
Icon="{ui:BitmapIcon Source=/Assets/Settings/Icons/CropAndLock.png}" />
<NavigationViewItem
x:Name="FancyZonesNavigationItem"
x:Uid="Shell_FancyZones"
helpers:NavHelper.NavigateTo="views:FancyZonesPage"
AutomationProperties.AutomationId="FancyZonesNavItem"
Icon="{ui:BitmapIcon Source=/Assets/Settings/Icons/FancyZones.png}" />
<NavigationViewItem
x:Name="WorkspacesNavigationItem"
x:Uid="Shell_Workspaces"
helpers:NavHelper.NavigateTo="views:WorkspacesPage"
AutomationProperties.AutomationId="WorkspacesNavItem"
Icon="{ui:BitmapIcon Source=/Assets/Settings/Icons/Workspaces.png}" />
</NavigationViewItem.MenuItems>
</NavigationViewItem>
<!-- Input / Output -->
<NavigationViewItem
x:Name="InputOutputNavigationItem"
x:Uid="Shell_TopLevelInputOutput"
AutomationProperties.AutomationId="InputOutputNavItem"
Icon="{ui:BitmapIcon Source=/Assets/Settings/Icons/InputOutput.png}"
SelectsOnInvoked="False">
<NavigationViewItem.MenuItems>
<NavigationViewItem
x:Name="KeyboardManagerNavigationItem"
x:Uid="Shell_KeyboardManager"
helpers:NavHelper.NavigateTo="views:KeyboardManagerPage"
AutomationProperties.AutomationId="KeyboardManagerNavItem"
Icon="{ui:BitmapIcon Source=/Assets/Settings/Icons/KeyboardManager.png}" />
<!-- Find my mouse -->
<!-- Mouse Highlighter -->
<NavigationViewItem
x:Name="MouseUtilitiesNavigationItem"
x:Uid="Shell_MouseUtilities"
helpers:NavHelper.NavigateTo="views:MouseUtilsPage"
AutomationProperties.AutomationId="MouseUtilitiesNavItem"
Icon="{ui:BitmapIcon Source=/Assets/Settings/Icons/MouseUtils.png}" />
<NavigationViewItem
x:Name="MouseWithoutBordersNavigationItem"
x:Uid="Shell_MouseWithoutBorders"
helpers:NavHelper.NavigateTo="views:MouseWithoutBordersPage"
AutomationProperties.AutomationId="MouseWithoutBordersNavItem"
Icon="{ui:BitmapIcon Source=/Assets/Settings/Icons/MouseWithoutBorders.png}" />
<NavigationViewItem
x:Name="QuickAccentNavigationItem"
x:Uid="Shell_QuickAccent"
helpers:NavHelper.NavigateTo="views:PowerAccentPage"
AutomationProperties.AutomationId="QuickAccentNavItem"
Icon="{ui:BitmapIcon Source=/Assets/Settings/Icons/QuickAccent.png}" />
</NavigationViewItem.MenuItems>
</NavigationViewItem>
<!-- File Management -->
<NavigationViewItem
x:Name="FileManagementNavigationItem"
x:Uid="Shell_TopLevelFileManagement"
AutomationProperties.AutomationId="FileManagementNavItem"
Icon="{ui:BitmapIcon Source=/Assets/Settings/Icons/FileManagement.png}"
SelectsOnInvoked="False">
<NavigationViewItem.MenuItems>
<NavigationViewItem
x:Name="PowerPreviewNavigationItem"
x:Uid="Shell_PowerPreview"
helpers:NavHelper.NavigateTo="views:PowerPreviewPage"
AutomationProperties.AutomationId="PowerPreviewNavItem"
Icon="{ui:BitmapIcon Source=/Assets/Settings/Icons/FileExplorerPreview.png}" />
<!-- File Explorer Thumbnails -->
<NavigationViewItem
x:Name="FileLocksmithNavigationItem"
x:Uid="Shell_FileLocksmith"
helpers:NavHelper.NavigateTo="views:FileLocksmithPage"
AutomationProperties.AutomationId="FileLocksmithNavItem"
Icon="{ui:BitmapIcon Source=/Assets/Settings/Icons/FileLocksmith.png}" />
<NavigationViewItem
x:Name="ImageResizerNavigationItem"
x:Uid="Shell_ImageResizer"
helpers:NavHelper.NavigateTo="views:ImageResizerPage"
AutomationProperties.AutomationId="ImageResizerNavItem"
Icon="{ui:BitmapIcon Source=/Assets/Settings/Icons/ImageResizer.png}" />
<NavigationViewItem
x:Name="NewPlusNavigationItem"
x:Uid="NewPlus_Product_Name"
helpers:NavHelper.NavigateTo="views:NewPlusPage"
AutomationProperties.AutomationId="NewPlusNavItem"
Icon="{ui:BitmapIcon Source=/Assets/Settings/Icons/NewPlus.png}" />
<NavigationViewItem
x:Name="PeekNavigationItem"
x:Uid="Shell_Peek"
helpers:NavHelper.NavigateTo="views:PeekPage"
AutomationProperties.AutomationId="PeekNavItem"
Icon="{ui:BitmapIcon Source=/Assets/Settings/Icons/Peek.png}" />
<NavigationViewItem
x:Name="PowerRenameNavigationItem"
x:Uid="Shell_PowerRename"
helpers:NavHelper.NavigateTo="views:PowerRenamePage"
AutomationProperties.AutomationId="PowerRenameNavItem"
Icon="{ui:BitmapIcon Source=/Assets/Settings/Icons/PowerRename.png}" />
</NavigationViewItem.MenuItems>
</NavigationViewItem>
<!-- Advanced -->
<NavigationViewItem
x:Name="AdvancedNavigationItem"
x:Uid="Shell_TopLevelAdvanced"
AutomationProperties.AutomationId="AdvancedNavItem"
Icon="{ui:BitmapIcon Source=/Assets/Settings/Icons/Advanced.png}"
SelectsOnInvoked="False">
<NavigationViewItem.MenuItems>
<NavigationViewItem
x:Name="CmdNotFoundNavigationItem"
x:Uid="Shell_CmdNotFound"
helpers:NavHelper.NavigateTo="views:CmdNotFoundPage"
AutomationProperties.AutomationId="CmdNotFoundNavItem"
Icon="{ui:BitmapIcon Source=/Assets/Settings/Icons/CommandNotFound.png}" />
<NavigationViewItem
x:Name="EnvironmentVariablesNavigationItem"
x:Uid="Shell_EnvironmentVariables"
helpers:NavHelper.NavigateTo="views:EnvironmentVariablesPage"
AutomationProperties.AutomationId="EnvironmentVariablesNavItem"
Icon="{ui:BitmapIcon Source=/Assets/Settings/Icons/EnvironmentVariables.png}" />
<NavigationViewItem
x:Name="HostsNavigationItem"
x:Uid="Shell_Hosts"
helpers:NavHelper.NavigateTo="views:HostsPage"
AutomationProperties.AutomationId="HostsNavItem"
Icon="{ui:BitmapIcon Source=/Assets/Settings/Icons/Hosts.png}" />
<NavigationViewItem
x:Name="RegistryPreviewNavigationItem"
x:Uid="Shell_RegistryPreview"
helpers:NavHelper.NavigateTo="views:RegistryPreviewPage"
AutomationProperties.AutomationId="RegistryPreviewNavItem"
Icon="{ui:BitmapIcon Source=/Assets/Settings/Icons/RegistryPreview.png}" />
</NavigationViewItem.MenuItems>
</NavigationViewItem>
@@ -323,19 +393,27 @@
<NavigationView.PaneFooter>
<StackPanel Orientation="Vertical">
<NavigationViewItem
x:Name="OOBENavigationItem"
x:Uid="OOBE_NavViewItem"
AutomationProperties.AutomationId="OOBENavItem"
Icon="{ui:FontIcon Glyph=&#xF133;}"
Tapped="OOBEItem_Tapped" />
<NavigationViewItem
x:Name="WhatIsNewNavigationItem"
x:Uid="WhatIsNew_NavViewItem"
AutomationProperties.AutomationId="WhatIsNewNavItem"
Icon="{ui:FontIcon Glyph=&#xE789;}"
Tapped="WhatIsNewItem_Tapped" />
<NavigationViewItem
x:Name="FeedbackNavigationItem"
x:Uid="Feedback_NavViewItem"
AutomationProperties.AutomationId="FeedbackNavItem"
Icon="{ui:FontIcon Glyph=&#xED15;}"
Tapped="FeedbackItem_Tapped" />
<NavigationViewItem
x:Name="CloseNavigationItem"
x:Uid="Close_NavViewItem"
AutomationProperties.AutomationId="CloseNavItem"
Icon="{ui:FontIcon Glyph=&#xE7E8;}"
Tapped="Close_Tapped"
Visibility="{x:Bind ViewModel.ShowCloseMenu, Mode=OneWay}" />