mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-05 10:46:33 +02:00
- [ ] Closes: #42249 Contribution to https://github.com/microsoft/PowerToys/issues/40701
This commit is contained in:
@@ -617,6 +617,8 @@ namespace MouseUtils.UITests
|
||||
|
||||
private void LaunchFromSetting(bool reload = false, bool launchAsAdmin = false)
|
||||
{
|
||||
Session = RestartScopeExe("FindMyMouse,MouseHighlighter,MouseJump,MousePointerCrosshairs,CursorWrap");
|
||||
|
||||
// this.Session.Attach(PowerToysModule.PowerToysSettings);
|
||||
this.Session.SetMainWindowSize(WindowSize.Large);
|
||||
|
||||
|
||||
@@ -105,6 +105,7 @@ public sealed partial class SettingsWindow : WindowEx,
|
||||
"Extensions" => typeof(ExtensionsPage),
|
||||
_ => null,
|
||||
};
|
||||
|
||||
if (pageType is not null)
|
||||
{
|
||||
NavFrame.Navigate(pageType);
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using FancyZonesEditor.Models;
|
||||
@@ -49,19 +50,16 @@ namespace UITests_FancyZones
|
||||
[TestInitialize]
|
||||
public void TestInitialize()
|
||||
{
|
||||
// ClearOpenWindows
|
||||
Session.KillAllProcessesByName("PowerToys");
|
||||
ClearOpenWindows();
|
||||
|
||||
// kill all processes related to FancyZones Editor to ensure a clean state
|
||||
Session.KillAllProcessesByName("PowerToys.FancyZonesEditor");
|
||||
|
||||
AppZoneHistory.DeleteFile();
|
||||
this.RestartScopeExe();
|
||||
FancyZonesEditorHelper.Files.Restore();
|
||||
|
||||
// Set a custom layout with 1 subzones and clear app zone history
|
||||
SetupCustomLayouts();
|
||||
|
||||
RestartScopeExe("Hosts");
|
||||
Thread.Sleep(2000);
|
||||
|
||||
// Get the current mouse button setting
|
||||
nonPrimaryMouseButton = SystemInformation.MouseButtonsSwapped ? "Left" : "Right";
|
||||
|
||||
@@ -72,99 +70,6 @@ namespace UITests_FancyZones
|
||||
LaunchFancyZones();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test Use Shift key to activate zones while dragging a window in FancyZones Zone Behaviour Settings
|
||||
/// <list type="bullet">
|
||||
/// <item>
|
||||
/// <description>Verifies that holding Shift while dragging shows all zones as expected.</description>
|
||||
/// </item>
|
||||
/// </list>
|
||||
/// </summary>
|
||||
[TestMethod("FancyZones.Settings.TestShowZonesOnShiftDuringDrag")]
|
||||
[TestCategory("FancyZones_Dragging #1")]
|
||||
public void TestShowZonesOnShiftDuringDrag()
|
||||
{
|
||||
string testCaseName = nameof(TestShowZonesOnShiftDuringDrag);
|
||||
Pane dragElement = Find<Pane>(By.Name("Non Client Input Sink Window")); // element to drag
|
||||
var offSet = ZoneSwitchHelper.GetOffset(dragElement, quarterX, quarterY);
|
||||
|
||||
var (initialColor, withShiftColor) = RunDragInteractions(
|
||||
preAction: () =>
|
||||
{
|
||||
dragElement.DragAndHold(offSet.Dx, offSet.Dy);
|
||||
},
|
||||
postAction: () =>
|
||||
{
|
||||
Session.PressKey(Key.Shift);
|
||||
Task.Delay(500).Wait();
|
||||
},
|
||||
releaseAction: () =>
|
||||
{
|
||||
Session.ReleaseKey(Key.Shift);
|
||||
Task.Delay(5000).Wait(); // Optional: Wait for a moment to ensure window switch
|
||||
},
|
||||
testCaseName: testCaseName);
|
||||
|
||||
string zoneColorWithoutShift = GetOutWindowPixelColor(30);
|
||||
|
||||
Assert.AreNotEqual(initialColor, withShiftColor, $"[{testCaseName}] Zone display failed.");
|
||||
Assert.IsTrue(
|
||||
withShiftColor == inactivateColor || withShiftColor == highlightColor,
|
||||
$"[{testCaseName}] Zone display failed: withShiftColor was {withShiftColor}, expected {inactivateColor} or {highlightColor}.");
|
||||
Assert.AreEqual(inactivateColor, withShiftColor, $"[{testCaseName}] Zone display failed.");
|
||||
|
||||
Assert.AreEqual(zoneColorWithoutShift, initialColor, $"[{testCaseName}] Zone deactivated failed.");
|
||||
dragElement.ReleaseDrag();
|
||||
|
||||
Clean();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test dragging a window during Shift key press in FancyZones Zone Behaviour Settings
|
||||
/// <list type="bullet">
|
||||
/// <item>
|
||||
/// <description>Verifies that dragging activates zones as expected.</description>
|
||||
/// </item>
|
||||
/// </list>
|
||||
/// </summary>
|
||||
[TestMethod("FancyZones.Settings.TestShowZonesOnDragDuringShift")]
|
||||
[TestCategory("FancyZones_Dragging #2")]
|
||||
public void TestShowZonesOnDragDuringShift()
|
||||
{
|
||||
string testCaseName = nameof(TestShowZonesOnDragDuringShift);
|
||||
|
||||
var dragElement = Find<Pane>(By.Name("Non Client Input Sink Window"));
|
||||
var offSet = ZoneSwitchHelper.GetOffset(dragElement, quarterX, quarterY);
|
||||
|
||||
var (initialColor, withDragColor) = RunDragInteractions(
|
||||
preAction: () =>
|
||||
{
|
||||
dragElement.Drag(offSet.Dx, offSet.Dy);
|
||||
Session.PressKey(Key.Shift);
|
||||
},
|
||||
postAction: () =>
|
||||
{
|
||||
dragElement.DragAndHold(0, 0);
|
||||
Task.Delay(5000).Wait();
|
||||
},
|
||||
releaseAction: () =>
|
||||
{
|
||||
dragElement.ReleaseDrag();
|
||||
Session.ReleaseKey(Key.Shift);
|
||||
},
|
||||
testCaseName: testCaseName);
|
||||
|
||||
Assert.AreNotEqual(initialColor, withDragColor, $"[{testCaseName}] Zone color did not change; zone activation failed.");
|
||||
Assert.AreEqual(highlightColor, withDragColor, $"[{testCaseName}] Zone color did not match the highlight color; activation failed.");
|
||||
|
||||
// double check by app-zone-history.json
|
||||
string appZoneHistoryJson = AppZoneHistory.GetData();
|
||||
string? zoneNumber = ZoneSwitchHelper.GetZoneIndexSetByAppName(powertoysWindowName, appZoneHistoryJson);
|
||||
Assert.IsNull(zoneNumber, $"[{testCaseName}] AppZoneHistory layout was unexpectedly set.");
|
||||
|
||||
Clean();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test toggling zones using a non-primary mouse click during window dragging.
|
||||
/// <list type="bullet">
|
||||
@@ -178,14 +83,19 @@ namespace UITests_FancyZones
|
||||
public void TestToggleZonesWithNonPrimaryMouseClick()
|
||||
{
|
||||
string testCaseName = nameof(TestToggleZonesWithNonPrimaryMouseClick);
|
||||
var dragElement = Find<Pane>(By.Name("Non Client Input Sink Window"));
|
||||
var offSet = ZoneSwitchHelper.GetOffset(dragElement, quarterX, quarterY);
|
||||
|
||||
var windowRect = Session.GetMainWindowRect();
|
||||
int startX = windowRect.Left + 70;
|
||||
int startY = windowRect.Top + 25;
|
||||
int endX = startX + 300;
|
||||
int endY = startY + 300;
|
||||
|
||||
var (initialColor, withMouseColor) = RunDragInteractions(
|
||||
preAction: () =>
|
||||
{
|
||||
// activate zone
|
||||
dragElement.DragAndHold(offSet.Dx, offSet.Dy);
|
||||
Session.MoveMouseTo(startX, startY);
|
||||
Session.PerformMouseAction(MouseActionType.LeftDown);
|
||||
Session.MoveMouseTo(endX, endY);
|
||||
},
|
||||
postAction: () =>
|
||||
{
|
||||
@@ -195,7 +105,7 @@ namespace UITests_FancyZones
|
||||
},
|
||||
releaseAction: () =>
|
||||
{
|
||||
dragElement.ReleaseDrag();
|
||||
Session.PerformMouseAction(MouseActionType.LeftUp);
|
||||
},
|
||||
testCaseName: testCaseName);
|
||||
|
||||
@@ -204,8 +114,6 @@ namespace UITests_FancyZones
|
||||
|
||||
// check the zone color is activated
|
||||
Assert.AreEqual(highlightColor, initialColor, $"[{testCaseName}] Zone activation failed.");
|
||||
|
||||
Clean();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -221,32 +129,35 @@ namespace UITests_FancyZones
|
||||
public void TestShowZonesWhenShiftAndMouseOff()
|
||||
{
|
||||
string testCaseName = nameof(TestShowZonesWhenShiftAndMouseOff);
|
||||
Pane dragElement = Find<Pane>(By.Name("Non Client Input Sink Window"));
|
||||
var offSet = ZoneSwitchHelper.GetOffset(dragElement, quarterX, quarterY);
|
||||
|
||||
var windowRect = Session.GetMainWindowRect();
|
||||
int startX = windowRect.Left + 70;
|
||||
int startY = windowRect.Top + 25;
|
||||
int endX = startX + 300;
|
||||
int endY = startY + 300;
|
||||
|
||||
var (initialColor, withShiftColor) = RunDragInteractions(
|
||||
preAction: () =>
|
||||
{
|
||||
// activate zone
|
||||
dragElement.DragAndHold(offSet.Dx, offSet.Dy);
|
||||
Session.MoveMouseTo(startX, startY);
|
||||
Session.PerformMouseAction(MouseActionType.LeftDown);
|
||||
Session.MoveMouseTo(endX, endY);
|
||||
},
|
||||
postAction: () =>
|
||||
{
|
||||
// press Shift Key to deactivate zones
|
||||
Session.PressKey(Key.Shift);
|
||||
Task.Delay(500).Wait();
|
||||
Task.Delay(1000).Wait();
|
||||
},
|
||||
releaseAction: () =>
|
||||
{
|
||||
dragElement.ReleaseDrag();
|
||||
Session.PerformMouseAction(MouseActionType.LeftUp);
|
||||
Session.ReleaseKey(Key.Shift);
|
||||
},
|
||||
testCaseName: testCaseName);
|
||||
|
||||
Assert.AreEqual(highlightColor, initialColor, $"[{testCaseName}] Zone activation failed.");
|
||||
Assert.AreNotEqual(highlightColor, withShiftColor, $"[{testCaseName}] Zone deactivation failed.");
|
||||
|
||||
Clean();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -263,12 +174,17 @@ namespace UITests_FancyZones
|
||||
{
|
||||
string testCaseName = nameof(TestShowZonesWhenShiftAndMouseOn);
|
||||
|
||||
var dragElement = Find<Pane>(By.Name("Non Client Input Sink Window"));
|
||||
var offSet = ZoneSwitchHelper.GetOffset(dragElement, quarterX, quarterY);
|
||||
var windowRect = Session.GetMainWindowRect();
|
||||
int startX = windowRect.Left + 70;
|
||||
int startY = windowRect.Top + 25;
|
||||
int endX = startX + 300;
|
||||
int endY = startY + 300;
|
||||
var (initialColor, withShiftColor) = RunDragInteractions(
|
||||
preAction: () =>
|
||||
{
|
||||
dragElement.DragAndHold(offSet.Dx, offSet.Dy);
|
||||
Session.MoveMouseTo(startX, startY);
|
||||
Session.PerformMouseAction(MouseActionType.LeftDown);
|
||||
Session.MoveMouseTo(endX, endY);
|
||||
},
|
||||
postAction: () =>
|
||||
{
|
||||
@@ -279,7 +195,7 @@ namespace UITests_FancyZones
|
||||
},
|
||||
testCaseName: testCaseName);
|
||||
|
||||
Assert.AreEqual(inactivateColor, withShiftColor, $"[{testCaseName}] show zone failed.");
|
||||
Assert.AreEqual(highlightColor, withShiftColor, $"[{testCaseName}] show zone failed.");
|
||||
|
||||
Session.PerformMouseAction(
|
||||
nonPrimaryMouseButton == "Right" ? MouseActionType.RightClick : MouseActionType.LeftClick);
|
||||
@@ -288,9 +204,7 @@ namespace UITests_FancyZones
|
||||
Assert.AreEqual(initialColor, zoneColorWithMouse, $"[{nameof(TestShowZonesWhenShiftAndMouseOff)}] Zone deactivate failed.");
|
||||
|
||||
Session.ReleaseKey(Key.Shift);
|
||||
dragElement.ReleaseDrag();
|
||||
|
||||
Clean();
|
||||
Session.PerformMouseAction(MouseActionType.LeftUp);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -307,8 +221,6 @@ namespace UITests_FancyZones
|
||||
{
|
||||
var pixel = GetPixelWhenMakeDraggedWindow();
|
||||
Assert.AreNotEqual(pixel.PixelInWindow, pixel.TransPixel, $"[{nameof(TestMakeDraggedWindowTransparentOn)}] Window transparency failed.");
|
||||
|
||||
Clean();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -325,14 +237,103 @@ namespace UITests_FancyZones
|
||||
{
|
||||
var pixel = GetPixelWhenMakeDraggedWindow();
|
||||
Assert.AreEqual(pixel.PixelInWindow, pixel.TransPixel, $"[{nameof(TestMakeDraggedWindowTransparentOff)}] Window without transparency failed.");
|
||||
|
||||
Clean();
|
||||
}
|
||||
|
||||
private void Clean()
|
||||
/// <summary>
|
||||
/// Test Use Shift key to activate zones while dragging a window in FancyZones Zone Behaviour Settings
|
||||
/// <list type="bullet">
|
||||
/// <item>
|
||||
/// <description>Verifies that holding Shift while dragging shows all zones as expected.</description>
|
||||
/// </item>
|
||||
/// </list>
|
||||
/// </summary>
|
||||
[TestMethod("FancyZones.Settings.TestShowZonesOnShiftDuringDrag")]
|
||||
[TestCategory("FancyZones_Dragging #1")]
|
||||
public void TestShowZonesOnShiftDuringDrag()
|
||||
{
|
||||
// clean app zone history file
|
||||
AppZoneHistory.DeleteFile();
|
||||
string testCaseName = nameof(TestShowZonesOnShiftDuringDrag);
|
||||
|
||||
var windowRect = Session.GetMainWindowRect();
|
||||
int startX = windowRect.Left + 70;
|
||||
int startY = windowRect.Top + 25;
|
||||
int endX = startX + 300;
|
||||
int endY = startY + 300;
|
||||
|
||||
var (initialColor, withShiftColor) = RunDragInteractions(
|
||||
preAction: () =>
|
||||
{
|
||||
Session.MoveMouseTo(startX, startY);
|
||||
Session.PerformMouseAction(MouseActionType.LeftDown);
|
||||
Session.MoveMouseTo(endX, endY);
|
||||
},
|
||||
postAction: () =>
|
||||
{
|
||||
Session.PressKey(Key.Shift);
|
||||
Task.Delay(500).Wait();
|
||||
},
|
||||
releaseAction: () =>
|
||||
{
|
||||
Session.ReleaseKey(Key.Shift);
|
||||
Task.Delay(1000).Wait(); // Optional: Wait for a moment to ensure window switch
|
||||
},
|
||||
testCaseName: testCaseName);
|
||||
|
||||
string zoneColorWithoutShift = GetOutWindowPixelColor(30);
|
||||
|
||||
Assert.AreNotEqual(initialColor, withShiftColor, $"[{testCaseName}] Zone color did not change; zone activation failed.");
|
||||
Assert.AreEqual(highlightColor, withShiftColor, $"[{testCaseName}] Zone color did not match the highlight color; activation failed.");
|
||||
|
||||
Session.PerformMouseAction(MouseActionType.LeftUp);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test dragging a window during Shift key press in FancyZones Zone Behaviour Settings
|
||||
/// <list type="bullet">
|
||||
/// <item>
|
||||
/// <description>Verifies that dragging activates zones as expected.</description>
|
||||
/// </item>
|
||||
/// </list>
|
||||
/// </summary>
|
||||
[TestMethod("FancyZones.Settings.TestShowZonesOnDragDuringShift")]
|
||||
[TestCategory("FancyZones_Dragging #2")]
|
||||
public void TestShowZonesOnDragDuringShift()
|
||||
{
|
||||
string testCaseName = nameof(TestShowZonesOnDragDuringShift);
|
||||
|
||||
var windowRect = Session.GetMainWindowRect();
|
||||
int startX = windowRect.Left + 70;
|
||||
int startY = windowRect.Top + 25;
|
||||
int endX = startX + 300;
|
||||
int endY = startY + 300;
|
||||
|
||||
var (initialColor, withDragColor) = RunDragInteractions(
|
||||
preAction: () =>
|
||||
{
|
||||
Session.PressKey(Key.Shift);
|
||||
Task.Delay(100).Wait();
|
||||
},
|
||||
postAction: () =>
|
||||
{
|
||||
Session.MoveMouseTo(startX, startY);
|
||||
Session.PerformMouseAction(MouseActionType.LeftDown);
|
||||
Session.MoveMouseTo(endX, endY);
|
||||
Task.Delay(1000).Wait();
|
||||
},
|
||||
releaseAction: () =>
|
||||
{
|
||||
Session.PerformMouseAction(MouseActionType.LeftUp);
|
||||
Session.ReleaseKey(Key.Shift);
|
||||
Task.Delay(100).Wait();
|
||||
},
|
||||
testCaseName: testCaseName);
|
||||
|
||||
Assert.AreNotEqual(initialColor, withDragColor, $"[{testCaseName}] Zone color did not change; zone activation failed.");
|
||||
Assert.AreEqual(highlightColor, withDragColor, $"[{testCaseName}] Zone color did not match the highlight color; activation failed.");
|
||||
|
||||
// double check by app-zone-history.json
|
||||
string appZoneHistoryJson = AppZoneHistory.GetData();
|
||||
string? zoneNumber = ZoneSwitchHelper.GetZoneIndexSetByAppName(powertoysWindowName, appZoneHistoryJson);
|
||||
Assert.IsNull(zoneNumber, $"[{testCaseName}] AppZoneHistory layout was unexpectedly set.");
|
||||
}
|
||||
|
||||
// Helper method to ensure the desktop has no open windows by clicking the "Show Desktop" button
|
||||
@@ -352,7 +353,7 @@ namespace UITests_FancyZones
|
||||
desktopButtonName = "Show Desktop";
|
||||
}
|
||||
|
||||
this.Find<Microsoft.PowerToys.UITest.Button>(By.Name(desktopButtonName), 5000, true).Click(false, 500, 2000);
|
||||
this.Find<Microsoft.PowerToys.UITest.Button>(By.Name(desktopButtonName), 5000, true).Click(false, 500, 1000);
|
||||
}
|
||||
|
||||
// Setup custom layout with 1 subzones
|
||||
@@ -382,6 +383,11 @@ namespace UITests_FancyZones
|
||||
this.Scroll(6, "Down"); // Pull the settings page up to make sure the settings are visible
|
||||
ZoneBehaviourSettings(TestContext.TestName);
|
||||
|
||||
// Go back and forth to make sure settings applied
|
||||
this.Find<NavigationViewItem>("Workspaces").Click();
|
||||
Task.Delay(200).Wait();
|
||||
this.Find<NavigationViewItem>("FancyZones").Click();
|
||||
|
||||
this.Find<Microsoft.PowerToys.UITest.Button>(By.AccessibilityId("LaunchLayoutEditorButton")).Click(false, 500, 10000);
|
||||
this.Session.Attach(PowerToysModule.FancyZone);
|
||||
|
||||
@@ -435,22 +441,26 @@ namespace UITests_FancyZones
|
||||
// Get the mouse color of the pixel when make dragged window
|
||||
private (string PixelInWindow, string TransPixel) GetPixelWhenMakeDraggedWindow()
|
||||
{
|
||||
var dragElement = Find<Pane>(By.Name("Non Client Input Sink Window"));
|
||||
var windowRect = Session.GetMainWindowRect();
|
||||
int startX = windowRect.Left + 70;
|
||||
int startY = windowRect.Top + 25;
|
||||
int endX = startX + 100;
|
||||
int endY = startY + 100;
|
||||
|
||||
// maximize the window to make sure get pixel color more accurate
|
||||
dragElement.DoubleClick();
|
||||
Session.MoveMouseTo(startX, startY);
|
||||
|
||||
var offSet = ZoneSwitchHelper.GetOffset(dragElement, quarterX, quarterY);
|
||||
// Session.PerformMouseAction(MouseActionType.LeftDoubleClick);
|
||||
Session.PressKey(Key.Shift);
|
||||
dragElement.DragAndHold(offSet.Dx, offSet.Dy);
|
||||
Task.Delay(1000).Wait(); // Optional: Wait for a moment to ensure the window is in position
|
||||
Session.PerformMouseAction(MouseActionType.LeftDown);
|
||||
Session.MoveMouseTo(endX, endY);
|
||||
|
||||
Tuple<int, int> pos = GetMousePosition();
|
||||
string pixelInWindow = this.GetPixelColorString(pos.Item1, pos.Item2);
|
||||
Session.ReleaseKey(Key.Shift);
|
||||
Task.Delay(1000).Wait(); // Optional: Wait for a moment to ensure the window is in position
|
||||
Task.Delay(1000).Wait();
|
||||
string transPixel = this.GetPixelColorString(pos.Item1, pos.Item2);
|
||||
dragElement.ReleaseDrag();
|
||||
|
||||
Session.PerformMouseAction(MouseActionType.LeftUp);
|
||||
return (pixelInWindow, transPixel);
|
||||
}
|
||||
|
||||
|
||||
@@ -271,7 +271,7 @@ namespace UITests_FancyZones
|
||||
};
|
||||
FancyZonesEditorHelper.Files.AppliedLayoutsIOHelper.WriteData(appliedLayouts.Serialize(appliedLayoutsWrapper));
|
||||
|
||||
this.RestartScopeExe();
|
||||
RestartScopeExe("Hosts");
|
||||
}
|
||||
|
||||
[TestMethod("FancyZones.Settings.TestApplyHotKey")]
|
||||
@@ -598,10 +598,12 @@ namespace UITests_FancyZones
|
||||
this.TryReaction();
|
||||
int tries = 24;
|
||||
Pull(tries, "down"); // Pull the setting page up to make sure the setting is visible
|
||||
this.Find<ToggleSwitch>("Enable quick layout switch").Toggle(flag);
|
||||
this.Find<ToggleSwitch>("FancyZonesQuickLayoutSwitch").Toggle(flag);
|
||||
|
||||
tries = 24;
|
||||
Pull(tries, "up");
|
||||
// Go back and forth to make sure settings applied
|
||||
this.Find<NavigationViewItem>("Workspaces").Click();
|
||||
Task.Delay(200).Wait();
|
||||
this.Find<NavigationViewItem>("FancyZones").Click();
|
||||
}
|
||||
|
||||
private void TryReaction()
|
||||
|
||||
@@ -34,7 +34,7 @@ namespace UITests_FancyZones
|
||||
Session.KillAllProcessesByName("PowerToys.FancyZonesEditor");
|
||||
AppZoneHistory.DeleteFile();
|
||||
|
||||
this.RestartScopeExe();
|
||||
RestartScopeExe("Hosts");
|
||||
FancyZonesEditorHelper.Files.Restore();
|
||||
|
||||
// Set a custom layout with 1 subzones and clear app zone history
|
||||
@@ -137,7 +137,7 @@ namespace UITests_FancyZones
|
||||
Task.Delay(500).Wait(); // Optional: Wait for a moment to ensure window switch
|
||||
|
||||
activeWindowTitle = ZoneSwitchHelper.GetActiveWindowTitle();
|
||||
Assert.AreNotEqual(preWindow, activeWindowTitle);
|
||||
Assert.AreEqual(postWindow, activeWindowTitle);
|
||||
|
||||
Clean(); // close the windows
|
||||
}
|
||||
@@ -151,9 +151,23 @@ namespace UITests_FancyZones
|
||||
|
||||
var rect = Session.GetMainWindowRect();
|
||||
var (targetX, targetY) = ZoneSwitchHelper.GetScreenMargins(rect, 4);
|
||||
var offSet = ZoneSwitchHelper.GetOffset(hostsView, targetX, targetY);
|
||||
|
||||
DragWithShift(hostsView, offSet);
|
||||
// Snap first window (Hosts) to left zone using shift+drag with direct mouse movement
|
||||
var hostsRect = hostsView.Rect ?? throw new InvalidOperationException("Failed to get hosts window rect");
|
||||
int hostsStartX = hostsRect.Left + 70;
|
||||
int hostsStartY = hostsRect.Top + 25;
|
||||
|
||||
// For a 2-column layout, left zone is at approximately 1/4 of screen width
|
||||
int hostsEndX = rect.Left + (3 * (rect.Right - rect.Left) / 4);
|
||||
int hostsEndY = rect.Top + ((rect.Bottom - rect.Top) / 2);
|
||||
|
||||
Session.MoveMouseTo(hostsStartX, hostsStartY);
|
||||
Session.PerformMouseAction(MouseActionType.LeftDown);
|
||||
Session.PressKey(Key.Shift);
|
||||
Session.MoveMouseTo(hostsEndX, hostsEndY);
|
||||
Session.PerformMouseAction(MouseActionType.LeftUp);
|
||||
Session.ReleaseKey(Key.Shift);
|
||||
Task.Delay(500).Wait(); // Wait for snap to complete
|
||||
|
||||
string preWindow = ZoneSwitchHelper.GetActiveWindowTitle();
|
||||
|
||||
@@ -163,11 +177,26 @@ namespace UITests_FancyZones
|
||||
Pane settingsView = Find<Pane>(By.Name("Non Client Input Sink Window"));
|
||||
settingsView.DoubleClick(); // maximize the window
|
||||
|
||||
DragWithShift(settingsView, offSet);
|
||||
var windowRect = Session.GetMainWindowRect();
|
||||
var settingsRect = settingsView.Rect ?? throw new InvalidOperationException("Failed to get settings window rect");
|
||||
int settingsStartX = settingsRect.Left + 70;
|
||||
int settingsStartY = settingsRect.Top + 25;
|
||||
|
||||
// For a 2-column layout, right zone is at approximately 3/4 of screen width
|
||||
int settingsEndX = windowRect.Left + (3 * (windowRect.Right - windowRect.Left) / 4);
|
||||
int settingsEndY = windowRect.Top + ((windowRect.Bottom - windowRect.Top) / 2);
|
||||
|
||||
Session.MoveMouseTo(settingsStartX, settingsStartY);
|
||||
Session.PerformMouseAction(MouseActionType.LeftDown);
|
||||
Session.PressKey(Key.Shift);
|
||||
Session.MoveMouseTo(settingsEndX, settingsEndY);
|
||||
Session.PerformMouseAction(MouseActionType.LeftUp);
|
||||
Session.ReleaseKey(Key.Shift);
|
||||
Task.Delay(500).Wait(); // Wait for snap to complete
|
||||
|
||||
string appZoneHistoryJson = AppZoneHistory.GetData();
|
||||
|
||||
string? zoneIndexOfFileWindow = ZoneSwitchHelper.GetZoneIndexSetByAppName("PowerToys.Hosts.exe", appZoneHistoryJson); // explorer.exe
|
||||
string? zoneIndexOfFileWindow = ZoneSwitchHelper.GetZoneIndexSetByAppName("PowerToys.Hosts.exe", appZoneHistoryJson);
|
||||
string? zoneIndexOfPowertoys = ZoneSwitchHelper.GetZoneIndexSetByAppName("PowerToys.Settings.exe", appZoneHistoryJson);
|
||||
|
||||
// check the AppZoneHistory layout is set and in the same zone
|
||||
@@ -176,16 +205,6 @@ namespace UITests_FancyZones
|
||||
return (preWindow, powertoysWindowName);
|
||||
}
|
||||
|
||||
private void DragWithShift(Pane settingsView, (int Dx, int Dy) offSet)
|
||||
{
|
||||
Session.PressKey(Key.Shift);
|
||||
settingsView.DragAndHold(offSet.Dx, offSet.Dy);
|
||||
Task.Delay(1000).Wait(); // Wait for drag to start (optional)
|
||||
settingsView.ReleaseDrag();
|
||||
Task.Delay(1000).Wait(); // Wait after drag (optional)
|
||||
Session.ReleaseKey(Key.Shift);
|
||||
}
|
||||
|
||||
private static readonly CustomLayouts.CustomLayoutListWrapper CustomLayoutsList = new CustomLayouts.CustomLayoutListWrapper
|
||||
{
|
||||
CustomLayouts = new List<CustomLayouts.CustomLayoutWrapper>
|
||||
@@ -253,11 +272,14 @@ namespace UITests_FancyZones
|
||||
this.Scroll(9, "Down"); // Pull the setting page up to make sure the setting is visible
|
||||
bool switchWindowEnable = TestContext.TestName == "TestSwitchShortCutDisable" ? false : true;
|
||||
|
||||
this.Find<ToggleSwitch>("Switch between windows in the current zone").Toggle(switchWindowEnable);
|
||||
this.Find<ToggleSwitch>("FancyZonesWindowSwitchingToggle").Toggle(switchWindowEnable);
|
||||
|
||||
Task.Delay(500).Wait(); // Wait for the setting to be applied
|
||||
this.Scroll(9, "Up"); // Pull the setting page down to make sure the setting is visible
|
||||
this.Find<Button>("Launch layout editor").Click(false, 500, 5000);
|
||||
// Go back and forth to make sure settings applied
|
||||
this.Find<NavigationViewItem>("Workspaces").Click();
|
||||
Task.Delay(200).Wait();
|
||||
this.Find<NavigationViewItem>("FancyZones").Click();
|
||||
|
||||
this.Find<Button>("Open layout editor").Click(false, 500, 5000);
|
||||
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.
|
||||
@@ -273,7 +295,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>("Open layout editor").Click(false, 5000, 5000);
|
||||
this.Session.Attach(PowerToysModule.FancyZone);
|
||||
|
||||
// customLayoutData = FancyZonesEditorHelper.Files.CustomLayoutsIOHelper.GetData();
|
||||
@@ -301,11 +323,11 @@ namespace UITests_FancyZones
|
||||
Task.Delay(1000).Wait();
|
||||
|
||||
this.Find<ToggleSwitch>("Enable Hosts File Editor").Toggle(true);
|
||||
this.Find<ToggleSwitch>("Launch as administrator").Toggle(launchAsAdmin);
|
||||
this.Find<ToggleSwitch>("Open as administrator").Toggle(launchAsAdmin);
|
||||
this.Find<ToggleSwitch>("Show a warning at startup").Toggle(showWarning);
|
||||
|
||||
// launch Hosts File Editor
|
||||
this.Find<Button>("Launch Hosts File Editor").Click();
|
||||
this.Find<Button>("Open Hosts File Editor").Click();
|
||||
|
||||
Task.Delay(5000).Wait();
|
||||
}
|
||||
|
||||
@@ -124,9 +124,6 @@ public class PeekFilePreviewTests : UITestBase
|
||||
settings["properties"] = properties;
|
||||
});
|
||||
|
||||
// Disable all modules except Peek in global settings
|
||||
SettingsConfigHelper.ConfigureGlobalModuleSettings("Peek");
|
||||
|
||||
Debug.WriteLine("Successfully updated all settings - Peek shortcut configured and all modules except Peek disabled");
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -138,6 +135,7 @@ public class PeekFilePreviewTests : UITestBase
|
||||
[TestInitialize]
|
||||
public void TestInitialize()
|
||||
{
|
||||
RestartScopeExe("Peek");
|
||||
Session.CloseMainWindow();
|
||||
SendKeys(Key.Win, Key.M);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user