Light Switch: Updating UI tests (#42225)

Updating UI tests to match new UI
This commit is contained in:
Jaylyn Barbee
2025-10-07 15:20:49 -04:00
committed by GitHub
parent e04e6a11d1
commit 3e213165a8
3 changed files with 62 additions and 13 deletions

View File

@@ -150,7 +150,7 @@ namespace LightSwitch.UITests
var modeCombobox = testBase.Session.Find<Element>(By.AccessibilityId("ModeSelection_LightSwitch"), 5000); var modeCombobox = testBase.Session.Find<Element>(By.AccessibilityId("ModeSelection_LightSwitch"), 5000);
Assert.IsNotNull(modeCombobox, "Mode combobox not found."); Assert.IsNotNull(modeCombobox, "Mode combobox not found.");
var neededTabs = 5; var neededTabs = 6;
if (modeCombobox.Text != "Manual") if (modeCombobox.Text != "Manual")
{ {
@@ -167,7 +167,7 @@ namespace LightSwitch.UITests
Assert.IsNotNull(timeline, "Timeline not found."); Assert.IsNotNull(timeline, "Timeline not found.");
var helpText = timeline.GetAttribute("HelpText"); var helpText = timeline.GetAttribute("HelpText");
string originalStartValue = GetHelpTextValue(helpText, "Start"); string originalEndValue = GetHelpTextValue(helpText, "End");
for (int i = 0; i < neededTabs; i++) for (int i = 0; i < neededTabs; i++)
{ {
@@ -179,12 +179,12 @@ namespace LightSwitch.UITests
testBase.Session.SendKeys(Key.Enter); testBase.Session.SendKeys(Key.Enter);
helpText = timeline.GetAttribute("HelpText"); helpText = timeline.GetAttribute("HelpText");
string updatedStartValue = GetHelpTextValue(helpText, "Start"); string updatedEndValue = GetHelpTextValue(helpText, "End");
Assert.AreNotEqual(originalStartValue, updatedStartValue, "Timeline start time should have been updated."); Assert.AreNotEqual(originalEndValue, updatedEndValue, "Timeline end time should have been updated.");
helpText = timeline.GetAttribute("HelpText"); helpText = timeline.GetAttribute("HelpText");
string originalEndValue = GetHelpTextValue(helpText, "End"); string originalStartValue = GetHelpTextValue(helpText, "Start");
testBase.Session.SendKeys(Key.Tab); testBase.Session.SendKeys(Key.Tab);
testBase.Session.SendKeys(Key.Enter); testBase.Session.SendKeys(Key.Enter);
@@ -192,9 +192,9 @@ namespace LightSwitch.UITests
testBase.Session.SendKeys(Key.Enter); testBase.Session.SendKeys(Key.Enter);
helpText = timeline.GetAttribute("HelpText"); helpText = timeline.GetAttribute("HelpText");
string updatedEndValue = GetHelpTextValue(helpText, "End"); string updatedStartValue = GetHelpTextValue(helpText, "Start");
Assert.AreNotEqual(originalEndValue, updatedEndValue, "Timeline end time should have been updated."); Assert.AreNotEqual(originalStartValue, updatedStartValue, "Timeline start time should have been updated.");
} }
/// <summary> /// <summary>
@@ -259,11 +259,7 @@ namespace LightSwitch.UITests
// Click the select city button // Click the select city button
var setLocationButton = testBase.Session.Find<Element>(By.AccessibilityId("SetLocationButton_LightSwitch"), 5000); var setLocationButton = testBase.Session.Find<Element>(By.AccessibilityId("SetLocationButton_LightSwitch"), 5000);
Assert.IsNotNull(setLocationButton, "Set location button not found."); Assert.IsNotNull(setLocationButton, "Set location button not found.");
setLocationButton.Click(); setLocationButton.Click(msPostAction: 8000);
var syncLocationButton = testBase.Session.Find<Element>(By.AccessibilityId("SyncLocationButton_LightSwitch"), 5000);
Assert.IsNotNull(syncLocationButton, "Sync location button not found.");
syncLocationButton.Click(msPostAction: 8000);
var latLong = testBase.Session.Find<Element>(By.AccessibilityId("LocationResultText_LightSwitch"), 5000); var latLong = testBase.Session.Find<Element>(By.AccessibilityId("LocationResultText_LightSwitch"), 5000);
Assert.IsFalse(string.IsNullOrWhiteSpace(latLong.Text)); Assert.IsFalse(string.IsNullOrWhiteSpace(latLong.Text));
@@ -305,6 +301,7 @@ namespace LightSwitch.UITests
string originalStartValue = GetHelpTextValue(helpText, "Start"); string originalStartValue = GetHelpTextValue(helpText, "Start");
sunriseOffset.Click(); sunriseOffset.Click();
testBase.Session.SendKeys(Key.Up);
helpText = timeline.GetAttribute("HelpText"); helpText = timeline.GetAttribute("HelpText");
string updatedStartValue = GetHelpTextValue(helpText, "Start"); string updatedStartValue = GetHelpTextValue(helpText, "Start");
@@ -319,6 +316,7 @@ namespace LightSwitch.UITests
string originalEndValue = GetHelpTextValue(helpText, "End"); string originalEndValue = GetHelpTextValue(helpText, "End");
sunsetOffset.Click(); sunsetOffset.Click();
testBase.Session.SendKeys(Key.Up);
helpText = timeline.GetAttribute("HelpText"); helpText = timeline.GetAttribute("HelpText");
string updatedEndValue = GetHelpTextValue(helpText, "End"); string updatedEndValue = GetHelpTextValue(helpText, "End");
@@ -338,9 +336,15 @@ namespace LightSwitch.UITests
var scrollViewer = testBase.Session.Find<Element>(By.AccessibilityId("PageScrollViewer")); var scrollViewer = testBase.Session.Find<Element>(By.AccessibilityId("PageScrollViewer"));
systemCheckbox.EnsureVisible(scrollViewer); systemCheckbox.EnsureVisible(scrollViewer);
// How do I handle when something is off screen? int neededTabs = 10;
if (!systemCheckbox.Selected) if (!systemCheckbox.Selected)
{ {
for (int i = 0; i < neededTabs; i++)
{
testBase.Session.SendKeys(Key.Tab);
}
systemCheckbox.Click(); systemCheckbox.Click();
} }

View File

@@ -8,6 +8,7 @@ using System.Globalization;
using Microsoft.PowerToys.Settings.UI.Helpers; using Microsoft.PowerToys.Settings.UI.Helpers;
using Microsoft.UI.Xaml; using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Automation; using Microsoft.UI.Xaml.Automation;
using Microsoft.UI.Xaml.Automation.Peers;
using Microsoft.UI.Xaml.Controls; using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Shapes; using Microsoft.UI.Xaml.Shapes;
using Windows.Foundation; using Windows.Foundation;
@@ -79,6 +80,11 @@ namespace Microsoft.PowerToys.Settings.UI.Controls
this.IsEnabledChanged += Timeline_IsEnabledChanged; this.IsEnabledChanged += Timeline_IsEnabledChanged;
} }
protected override AutomationPeer OnCreateAutomationPeer()
{
return new TimelineAutomationPeer(this);
}
private void Timeline_Loaded(object sender, RoutedEventArgs e) private void Timeline_Loaded(object sender, RoutedEventArgs e)
{ {
CheckEnabledState(); CheckEnabledState();

View File

@@ -0,0 +1,39 @@
// 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 Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Automation;
using Microsoft.UI.Xaml.Automation.Peers;
namespace Microsoft.PowerToys.Settings.UI.Controls
{
public partial class TimelineAutomationPeer : FrameworkElementAutomationPeer
{
public TimelineAutomationPeer(Timeline owner)
: base(owner)
{
}
protected override string GetClassNameCore() => "Timeline";
protected override AutomationControlType GetAutomationControlTypeCore()
=> AutomationControlType.Custom;
protected override string GetAutomationIdCore()
{
var owner = (Timeline)Owner;
var id = AutomationProperties.GetAutomationId(owner);
return string.IsNullOrEmpty(id) ? base.GetAutomationIdCore() : id;
}
protected override string GetNameCore()
{
var owner = (Timeline)Owner;
var name = AutomationProperties.GetName(owner);
return !string.IsNullOrEmpty(name)
? name
: $"Timeline from {owner.StartTime} to {owner.EndTime}";
}
}
}