diff --git a/src/common/UITestAutomation/Element/Element.cs b/src/common/UITestAutomation/Element/Element.cs index 0ab23dba78..144b6c082a 100644 --- a/src/common/UITestAutomation/Element/Element.cs +++ b/src/common/UITestAutomation/Element/Element.cs @@ -113,9 +113,10 @@ namespace Microsoft.PowerToys.UITest /// Click the UI element. /// /// If true, performs a right-click; otherwise, performs a left-click. Default value is false - public virtual void Click(bool rightClick = false) + public virtual void Click(bool rightClick = false, int msPreAction = 500, int msPostAction = 500) { - PerformAction((actions, windowElement) => + PerformAction( + (actions, windowElement) => { actions.MoveToElement(windowElement); @@ -132,7 +133,9 @@ namespace Microsoft.PowerToys.UITest } actions.Build().Perform(); - }); + }, + msPreAction, + msPostAction); } /// diff --git a/src/common/UITestAutomation/Element/NavigationViewItem.cs b/src/common/UITestAutomation/Element/NavigationViewItem.cs index 0a71d9a321..3d1171208b 100644 --- a/src/common/UITestAutomation/Element/NavigationViewItem.cs +++ b/src/common/UITestAutomation/Element/NavigationViewItem.cs @@ -24,9 +24,12 @@ namespace Microsoft.PowerToys.UITest /// Click the ListItem element. /// /// If true, performs a right-click; otherwise, performs a left-click. Default value is false - public override void Click(bool rightClick = false) + /// Pre action delay in milliseconds. Default value is 500 + /// Post action delay in milliseconds. Default value is 500 + public override void Click(bool rightClick = false, int msPreAction = 500, int msPostAction = 500) { - PerformAction((actions, windowElement) => + PerformAction( + (actions, windowElement) => { actions.MoveToElement(windowElement, 10, 10); @@ -40,7 +43,9 @@ namespace Microsoft.PowerToys.UITest } actions.Build().Perform(); - }); + }, + msPreAction, + msPostAction); } /// diff --git a/src/common/UITestAutomation/Session.cs b/src/common/UITestAutomation/Session.cs index d4201f7579..278ea1ff70 100644 --- a/src/common/UITestAutomation/Session.cs +++ b/src/common/UITestAutomation/Session.cs @@ -519,9 +519,12 @@ namespace Microsoft.PowerToys.UITest /// Performs a mouse action based on the specified action type. /// /// The mouse action to perform. - public void PerformMouseAction(MouseActionType action) + /// Pre-action delay in milliseconds. + /// Post-action delay in milliseconds. + public void PerformMouseAction(MouseActionType action, int msPreAction = 500, int msPostAction = 500) { - PerformAction(() => + PerformAction( + () => { switch (action) { @@ -567,7 +570,9 @@ namespace Microsoft.PowerToys.UITest default: throw new ArgumentException("Unsupported mouse action.", nameof(action)); } - }); + }, + msPreAction, + msPostAction); } /// diff --git a/src/modules/MouseUtils/MouseUtils.UITests/FindMyMouseTests.cs b/src/modules/MouseUtils/MouseUtils.UITests/FindMyMouseTests.cs index f90e084cf2..ea326bcaf1 100644 --- a/src/modules/MouseUtils/MouseUtils.UITests/FindMyMouseTests.cs +++ b/src/modules/MouseUtils/MouseUtils.UITests/FindMyMouseTests.cs @@ -9,6 +9,7 @@ using System.Xml.Linq; using Microsoft.PowerToys.UITest; using Microsoft.VisualStudio.TestTools.UnitTesting; using Windows.Devices.Printers; +using static System.Windows.Forms.VisualStyles.VisualStyleElement.Window; namespace MouseUtils.UITests { @@ -48,10 +49,11 @@ namespace MouseUtils.UITests if (foundCustom != null) { foundCustom.Find("Enable Find My Mouse").Toggle(true); + CheckAnimationEnable(ref foundCustom); // foundCustom.Find("Enable Find My Mouse").Toggle(false); SetFindMyMouseActivationMethod(ref foundCustom, "Press Left Control twice"); - + Assert.IsNotNull(foundCustom, "Find My Mouse group not found."); SetFindMyMouseAppearanceBehavior(ref foundCustom, ref settings); var excludedApps = foundCustom.Find("Excluded apps"); @@ -84,8 +86,7 @@ namespace MouseUtils.UITests Task.Delay(1000).Wait(); // MouseSimulator.LeftClick(); - Session.PerformMouseAction(MouseActionType.LeftClick); - Task.Delay(1000).Wait(); + Session.PerformMouseAction(MouseActionType.LeftClick, 500, 1000); VerifySpotlightDisappears(ref settings); } @@ -109,7 +110,7 @@ namespace MouseUtils.UITests // foundCustom.Find("Enable Find My Mouse").Toggle(false); SetFindMyMouseActivationMethod(ref foundCustom, "Press Left Control twice"); - + Assert.IsNotNull(foundCustom); SetFindMyMouseAppearanceBehavior(ref foundCustom, ref settings); var excludedApps = foundCustom.Find("Excluded apps"); @@ -167,6 +168,7 @@ namespace MouseUtils.UITests // foundCustom.Find("Enable Find My Mouse").Toggle(false); SetFindMyMouseActivationMethod(ref foundCustom, "Press Left Control twice"); + Assert.IsNotNull(foundCustom, "Find My Mouse group not found."); // SetFindMyMouseAppearanceBehavior(ref foundCustom, ref settings); var excludedApps = foundCustom.Find("Excluded apps"); @@ -273,7 +275,7 @@ namespace MouseUtils.UITests VerifySpotlightAppears(ref settings); } - private void SetFindMyMouseActivationMethod(ref Custom foundCustom, string method) + private void SetFindMyMouseActivationMethod(ref Custom? foundCustom, string method) { Assert.IsNotNull(foundCustom); var groupActivation = foundCustom.Find("Activation method"); @@ -360,8 +362,7 @@ namespace MouseUtils.UITests Task.Delay(100).Wait(); rgbHexEdit2.SetText(settings.SpotlightColor); Task.Delay(100).Wait(); - spotlightColorButton.Click(); - Task.Delay(1000).Wait(); + spotlightColorButton.Click(false, 500, 1500); // Set the overlay opacity to overlayOpacity% var overlayOpacitySlider = foundCustom.Find("Overlay opacity (%)"); @@ -432,6 +433,13 @@ namespace MouseUtils.UITests return true; } + private void CheckAnimationEnable(ref Custom? foundCustom) + { + Assert.IsNotNull(foundCustom, "Find My Mouse group not found."); + var animationDisabledWarning = foundCustom.Find("Animations are disabled in your system settings"); + Assert.IsNull(animationDisabledWarning); + } + private void LaunchFromSetting(bool showWarning = false, bool launchAsAdmin = false) { // this.Session.Attach(PowerToysModule.PowerToysSettings);