diff --git a/src/common/UITestAutomation/Session.cs b/src/common/UITestAutomation/Session.cs index e6d6448c26..7de3ff3978 100644 --- a/src/common/UITestAutomation/Session.cs +++ b/src/common/UITestAutomation/Session.cs @@ -33,6 +33,11 @@ namespace Microsoft.PowerToys.UITest /// public IntPtr MainWindowHandler { get; private set; } + /// + /// Gets Init Scope + /// + public PowerToysModule InitScope { get; private set; } + /// /// Gets the RunAsAdmin flag. /// If true, the session is running as admin. @@ -46,9 +51,13 @@ namespace Microsoft.PowerToys.UITest this.MainWindowHandler = IntPtr.Zero; this.Root = root; this.WindowsDriver = windowsDriver; + this.InitScope = scope; - // Attach to the scope & reset MainWindowHandler - this.Attach(scope, size); + if (size != WindowSize.UnSpecified) + { + // Attach to the scope & reset MainWindowHandler + this.Attach(scope, size); + } } /// @@ -382,6 +391,12 @@ namespace Microsoft.PowerToys.UITest /// the height in pixel public void SetMainWindowSize(int width, int height) { + if (this.MainWindowHandler == IntPtr.Zero) + { + // Attach to the scope & reset MainWindowHandler + this.Attach(this.InitScope); + } + if (this.MainWindowHandler == IntPtr.Zero || width <= 0 || height <= 0) diff --git a/src/modules/MouseUtils/MouseUtils.UITests/FindMyMouseTests.cs b/src/modules/MouseUtils/MouseUtils.UITests/FindMyMouseTests.cs index 2ed67f4895..42b2e4c097 100644 --- a/src/modules/MouseUtils/MouseUtils.UITests/FindMyMouseTests.cs +++ b/src/modules/MouseUtils/MouseUtils.UITests/FindMyMouseTests.cs @@ -178,7 +178,77 @@ namespace MouseUtils.UITests { foundCustom.Find("Enable Find My Mouse").Toggle(true); - // foundCustom.Find("Enable Find My Mouse").Toggle(false); + foundCustom.Find("Enable Find My Mouse").Toggle(false); + + foundCustom.Find("Enable Find My Mouse").Toggle(true); + SetFindMyMouseActivationMethod(ref foundCustom, "Press Left Control twice"); + Assert.IsNotNull(foundCustom); + SetFindMyMouseAppearanceBehavior(ref foundCustom, ref settings); + + var excludedApps = foundCustom.Find("Excluded apps"); + if (excludedApps != null) + { + excludedApps.Click(); + excludedApps.Click(); + } + else + { + Assert.Fail("Activation method group not found."); + } + } + else + { + Assert.Fail("Find My Mouse group not found."); + } + + // [Test Case]Enable FindMyMouse. Then, without moving your mouse: Press Left Ctrl twice and verify the overlay appears. + // VerifySpotlightSettings(ref settings); + ActivateSpotlight(ref settings); + VerifySpotlightAppears(ref settings); + + // [Test Case] Disable FindMyMouse. Verify the overlay no longer appears when you press Left Ctrl twice + foundCustom.Find("Enable Find My Mouse").Toggle(false); + Task.Delay(1000).Wait(); + ActivateSpotlight(ref settings); + + VerifySpotlightDisappears(ref settings); + + // [Test Case] Press Left Ctrl twice and verify the overlay appears + foundCustom.Find("Enable Find My Mouse").Toggle(true); + ActivateSpotlight(ref settings); + VerifySpotlightAppears(ref settings); + + Session.PerformMouseAction(MouseActionType.LeftClick); + } + + [TestMethod] + public void TestDisableFindMyMouse3() + { + LaunchFromSetting(); + + var settings = new FindMyMouseSettings(); + settings.OverlayOpacity = "100"; + settings.Radius = "50"; + settings.InitialZoom = "1"; + settings.AnimationDuration = "0"; + settings.BackgroundColor = "000000"; + settings.SpotlightColor = "FFFFFF"; + var foundCustom = this.Find("Find My Mouse"); + + Assert.IsNotNull(foundCustom); + + if (CheckAnimationEnable(ref foundCustom)) + { + foundCustom = this.Find("Find My Mouse"); + } + + if (foundCustom != null) + { + foundCustom.Find("Enable Find My Mouse").Toggle(true); + + foundCustom.Find("Enable Find My Mouse").Toggle(false); + + foundCustom.Find("Enable Find My Mouse").Toggle(true); SetFindMyMouseActivationMethod(ref foundCustom, "Press Left Control twice"); Assert.IsNotNull(foundCustom); SetFindMyMouseAppearanceBehavior(ref foundCustom, ref settings); diff --git a/src/modules/MouseUtils/MouseUtils.UITests/MouseHighlighterTests.cs b/src/modules/MouseUtils/MouseUtils.UITests/MouseHighlighterTests.cs index ae889e417c..72f73d6886 100644 --- a/src/modules/MouseUtils/MouseUtils.UITests/MouseHighlighterTests.cs +++ b/src/modules/MouseUtils/MouseUtils.UITests/MouseHighlighterTests.cs @@ -129,6 +129,120 @@ namespace MouseUtils.UITests Task.Delay(500).Wait(); } + [TestMethod] + public void TestEnableMouseHighlighter2() + { + LaunchFromSetting(); + var foundCustom0 = this.Find("Find My Mouse"); + if (foundCustom0 != null) + { + foundCustom0.Find("Enable Find My Mouse").Toggle(false); + } + else + { + Assert.Fail("Find My Mouse custom not found."); + } + + var settings = new MouseHighlighterSettings(); + settings.PrimaryButtonHighlightColor = "FFFF0000"; + settings.SecondaryButtonHighlightColor = "FF00FF00"; + settings.AlwaysHighlightColor = "004cFF71"; + settings.Radius = "50"; + settings.FadeDelay = "0"; + settings.FadeDuration = "90"; + + var foundCustom = this.Find("Mouse Highlighter"); + if (foundCustom != null) + { + foundCustom.Find("Enable Mouse Highlighter").Toggle(true); + foundCustom.Find("Enable Mouse Highlighter").Toggle(false); + + var xy = Session.GetMousePosition(); + Session.MoveMouseTo(xy.Item1, xy.Item2 - 100); + + Session.PerformMouseAction(MouseActionType.ScrollDown); + Session.PerformMouseAction(MouseActionType.ScrollDown); + Session.PerformMouseAction(MouseActionType.ScrollDown); + foundCustom.Find("Enable Mouse Highlighter").Toggle(true); + + // Change the shortcut key for MouseHighlighter + // [TestCase]Change activation shortcut and test it + var activationShortcutButton = foundCustom.Find