Updated UI tests for Light Switch to match new UI

This commit is contained in:
Jaylyn Barbee
2025-10-07 12:36:39 -04:00
parent 7524dc9a79
commit 237d1d5537
4 changed files with 62 additions and 45 deletions

View File

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

View File

@@ -1,32 +0,0 @@
// 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.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.PowerToys.UITest;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace LightSwitch.UITests
{
[TestClass]
public class TestUserSelectedLocation : UITestBase
{
public TestUserSelectedLocation()
: base(PowerToysModule.PowerToysSettings, WindowSize.Large)
{
}
[TestMethod("LightSwitch.UserSelectedLocation")]
[TestCategory("Location")]
public void TestUserSelectedLocationUpdate()
{
TestHelper.InitializeTest(this, "user selected location test");
TestHelper.PerformUserSelectedLocationTest(this);
TestHelper.CleanupTest(this);
}
}
}

View File

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