diff --git a/src/tests/win-app-driver/FancyZonesTests/EditorCanvasZoneResizeTests.cs b/src/tests/win-app-driver/FancyZonesTests/EditorCanvasZoneResizeTests.cs deleted file mode 100644 index a191c5341f..0000000000 --- a/src/tests/win-app-driver/FancyZonesTests/EditorCanvasZoneResizeTests.cs +++ /dev/null @@ -1,301 +0,0 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using OpenQA.Selenium.Appium; -using OpenQA.Selenium.Appium.Windows; -using OpenQA.Selenium.Interactions; -using System.Windows.Forms; - -namespace PowerToysTests -{ - [TestClass] - public class FancyZonesEditorCanvasZoneResizeTests : FancyZonesEditor - { - private void MoveCorner(WindowsElement corner, bool shiftLeft, bool shiftUp, int xOffset, int yOffset) - { - int shiftX = shiftLeft ? -(corner.Rect.Width / 2) + 1 : (corner.Rect.Width / 2) - 1; - int shiftY = shiftUp ? -(corner.Rect.Height / 2) + 1 : (corner.Rect.Height / 2) - 1; - - new Actions(session).MoveToElement(corner) - .MoveByOffset(shiftX, shiftY) - .ClickAndHold().MoveByOffset(xOffset, yOffset).Release().Perform(); - } - - [TestMethod] - public void MoveTopBorder() - { - WindowsElement topBorder = session.FindElementByAccessibilityId("NResize"); - WindowsElement bottomBorder = session.FindElementByAccessibilityId("SResize"); - Assert.IsNotNull(topBorder); - Assert.IsNotNull(bottomBorder); - - int height = bottomBorder.Rect.Y - topBorder.Rect.Y; - - //up - new Actions(session).MoveToElement(topBorder).ClickAndHold().MoveByOffset(0, -5000).Release().Perform(); - Assert.IsTrue(topBorder.Rect.Y >= 0); - Assert.IsTrue(height < bottomBorder.Rect.Y - topBorder.Rect.Y); - height = bottomBorder.Rect.Y - topBorder.Rect.Y; - - //down - new Actions(session).MoveToElement(topBorder).ClickAndHold().MoveByOffset(0, 5000).Release().Perform(); - Assert.IsTrue(topBorder.Rect.Y <= bottomBorder.Rect.Y); - Assert.IsTrue(height > bottomBorder.Rect.Y - topBorder.Rect.Y); - } - - [TestMethod] - public void MoveBottomBorder() - { - WindowsElement topBorder = session.FindElementByAccessibilityId("NResize"); - WindowsElement bottomBorder = session.FindElementByAccessibilityId("SResize"); - Assert.IsNotNull(topBorder); - Assert.IsNotNull(bottomBorder); - - int height = bottomBorder.Rect.Y - topBorder.Rect.Y; - - //up - new Actions(session).MoveToElement(bottomBorder).ClickAndHold().MoveByOffset(0, -5000).Release().Perform(); - Assert.IsTrue(topBorder.Rect.Y <= bottomBorder.Rect.Y); - Assert.IsTrue(height > bottomBorder.Rect.Y - topBorder.Rect.Y); - height = bottomBorder.Rect.Y - topBorder.Rect.Y; - - //down - new Actions(session).MoveToElement(bottomBorder).ClickAndHold().MoveByOffset(0, 5000).Release().Perform(); - Assert.IsTrue(bottomBorder.Rect.Y <= Screen.PrimaryScreen.WorkingArea.Bottom); - Assert.IsTrue(height < bottomBorder.Rect.Y - topBorder.Rect.Y); - } - - [TestMethod] - public void MoveLeftBorder() - { - WindowsElement leftBorder = session.FindElementByAccessibilityId("WResize"); - WindowsElement rightBorder = session.FindElementByAccessibilityId("EResize"); - Assert.IsNotNull(leftBorder); - Assert.IsNotNull(rightBorder); - - int width = rightBorder.Rect.X - leftBorder.Rect.X; - - //to the left - new Actions(session).MoveToElement(leftBorder).ClickAndHold().MoveByOffset(-5000, 0).Release().Perform(); - Assert.IsTrue(leftBorder.Rect.Y <= Screen.PrimaryScreen.WorkingArea.Bottom); - Assert.IsTrue(width < rightBorder.Rect.X - leftBorder.Rect.X); - width = rightBorder.Rect.X - leftBorder.Rect.X; - - //to the right - new Actions(session).MoveToElement(leftBorder).ClickAndHold().MoveByOffset(5000, 0).Release().Perform(); - Assert.IsTrue(leftBorder.Rect.X <= rightBorder.Rect.X); - Assert.IsTrue(width > rightBorder.Rect.X - leftBorder.Rect.X); - } - - [TestMethod] - public void MoveRightBorder() - { - WindowsElement leftBorder = session.FindElementByAccessibilityId("WResize"); - WindowsElement rightBorder = session.FindElementByAccessibilityId("EResize"); - Assert.IsNotNull(leftBorder); - Assert.IsNotNull(rightBorder); - - int width = rightBorder.Rect.X - leftBorder.Rect.X; - - //to the left - new Actions(session).MoveToElement(rightBorder).ClickAndHold().MoveByOffset(-5000, 0).Release().Perform(); - Assert.IsTrue(leftBorder.Rect.X <= rightBorder.Rect.X); - Assert.IsTrue(width > rightBorder.Rect.X - leftBorder.Rect.X); - width = rightBorder.Rect.X - leftBorder.Rect.X; - - //to the right - new Actions(session).MoveToElement(rightBorder).ClickAndHold().MoveByOffset(5000, 0).Release().Perform(); - Assert.IsTrue(leftBorder.Rect.X <= Screen.PrimaryScreen.WorkingArea.Right); - Assert.IsTrue(width < rightBorder.Rect.X - leftBorder.Rect.X); - } - - [TestMethod] - public void MoveTopLeftCorner() - { - WindowsElement topLeftCorner = session.FindElementByAccessibilityId("NWResize"); - WindowsElement bottomBorder = session.FindElementByAccessibilityId("SResize"); - WindowsElement rightBorder = session.FindElementByAccessibilityId("EResize"); - Assert.IsNotNull(topLeftCorner); - Assert.IsNotNull(bottomBorder); - Assert.IsNotNull(rightBorder); - - int expectedWidth = rightBorder.Rect.X - topLeftCorner.Rect.X; - int expectedHeight = bottomBorder.Rect.Y - topLeftCorner.Rect.Y; - int actualWidth, actualHeight; - - //up-left - MoveCorner(topLeftCorner, true, true, -5000, -5000); - actualHeight = bottomBorder.Rect.Y - topLeftCorner.Rect.Y; - actualWidth = rightBorder.Rect.X - topLeftCorner.Rect.X; - - Assert.IsTrue(topLeftCorner.Rect.Y >= 0); - Assert.IsTrue(topLeftCorner.Rect.X >= 0); - Assert.IsTrue(actualHeight > expectedHeight); - Assert.IsTrue(actualWidth > expectedWidth); - - expectedHeight = actualHeight; - expectedWidth = actualWidth; - - //down-right - MoveCorner(topLeftCorner, true, true, 5000, 5000); - actualHeight = bottomBorder.Rect.Y - topLeftCorner.Rect.Y; - actualWidth = rightBorder.Rect.X - topLeftCorner.Rect.X; - - Assert.IsTrue(topLeftCorner.Rect.Y <= bottomBorder.Rect.Y); - Assert.IsTrue(topLeftCorner.Rect.X <= rightBorder.Rect.X); - Assert.IsTrue(actualHeight < expectedHeight); - Assert.IsTrue(actualWidth < expectedWidth); - } - - [TestMethod] - public void MoveTopRightCorner() - { - WindowsElement topRightCorner = session.FindElementByAccessibilityId("NEResize"); - WindowsElement bottomBorder = session.FindElementByAccessibilityId("SResize"); - WindowsElement leftBorder = session.FindElementByAccessibilityId("WResize"); - Assert.IsNotNull(topRightCorner); - Assert.IsNotNull(bottomBorder); - Assert.IsNotNull(leftBorder); - - int expectedWidth = topRightCorner.Rect.X - leftBorder.Rect.X; - int expectedHeight = bottomBorder.Rect.Y - topRightCorner.Rect.Y; - int actualWidth, actualHeight; - - //up-right - MoveCorner(topRightCorner, false, true, 5000, -5000); - actualHeight = bottomBorder.Rect.Y - topRightCorner.Rect.Y; - actualWidth = topRightCorner.Rect.X - leftBorder.Rect.X; - - Assert.IsTrue(topRightCorner.Rect.Y >= 0); - Assert.IsTrue(leftBorder.Rect.X <= Screen.PrimaryScreen.WorkingArea.Right); - Assert.IsTrue(actualHeight > expectedHeight); - Assert.IsTrue(actualWidth > expectedWidth); - - expectedHeight = actualHeight; - expectedWidth = actualWidth; - - //down-left - MoveCorner(topRightCorner, false, true, -5000, 5000); - actualHeight = bottomBorder.Rect.Y - topRightCorner.Rect.Y; - actualWidth = topRightCorner.Rect.X - leftBorder.Rect.X; - - Assert.IsTrue(topRightCorner.Rect.Y <= bottomBorder.Rect.Y); - Assert.IsTrue(topRightCorner.Rect.X >= leftBorder.Rect.X); - Assert.IsTrue(actualHeight < expectedHeight); - Assert.IsTrue(actualWidth < expectedWidth); - } - - [TestMethod] - public void MoveBottomLeftCorner() - { - WindowsElement bottomLeftCorner = session.FindElementByAccessibilityId("SWResize"); - WindowsElement topBorder = session.FindElementByAccessibilityId("NResize"); - WindowsElement rightBorder = session.FindElementByAccessibilityId("EResize"); - Assert.IsNotNull(bottomLeftCorner); - Assert.IsNotNull(topBorder); - Assert.IsNotNull(rightBorder); - - int expectedWidth = rightBorder.Rect.X - bottomLeftCorner.Rect.X; - int expectedHeight = bottomLeftCorner.Rect.Y - topBorder.Rect.Y; - int actualWidth, actualHeight; - - //up-left - MoveCorner(bottomLeftCorner, true, false, 5000, -5000); - actualHeight = bottomLeftCorner.Rect.Y - topBorder.Rect.Y; - actualWidth = rightBorder.Rect.X - bottomLeftCorner.Rect.X; - - Assert.IsTrue(bottomLeftCorner.Rect.Y >= topBorder.Rect.Y); - Assert.IsTrue(bottomLeftCorner.Rect.X <= rightBorder.Rect.X); - Assert.IsTrue(actualHeight < expectedHeight); - Assert.IsTrue(actualWidth < expectedWidth); - - expectedHeight = actualHeight; - expectedWidth = actualWidth; - - //down-right - MoveCorner(bottomLeftCorner, true, false, -5000, 5000); - actualHeight = bottomLeftCorner.Rect.Y - topBorder.Rect.Y; - actualWidth = rightBorder.Rect.X - bottomLeftCorner.Rect.X; - - Assert.IsTrue(bottomLeftCorner.Rect.Y <= Screen.PrimaryScreen.WorkingArea.Bottom); - Assert.IsTrue(bottomLeftCorner.Rect.X >= 0); - Assert.IsTrue(actualHeight > expectedHeight); - Assert.IsTrue(actualWidth > expectedWidth); - } - - [TestMethod] - public void MoveBottomRightCorner() - { - WindowsElement zone = session.FindElementByAccessibilityId("Caption"); - Assert.IsNotNull(zone, "Unable to move zone"); - new Actions(session).MoveToElement(zone).ClickAndHold().MoveByOffset(creatorWindow.Rect.Width / 2, 0).Release().Perform(); - WindowsElement bottomRightCorner = session.FindElementByAccessibilityId("SEResize"); - WindowsElement topBorder = session.FindElementByAccessibilityId("NResize"); - WindowsElement leftBorder = session.FindElementByAccessibilityId("WResize"); - Assert.IsNotNull(bottomRightCorner); - Assert.IsNotNull(topBorder); - Assert.IsNotNull(leftBorder); - - int expectedWidth = bottomRightCorner.Rect.X - leftBorder.Rect.X; - int expectedHeight = bottomRightCorner.Rect.Y - topBorder.Rect.Y; - int actualWidth, actualHeight; - - //up-left - MoveCorner(bottomRightCorner, false, false, -5000, -5000); - actualHeight = bottomRightCorner.Rect.Y - topBorder.Rect.Y; - actualWidth = bottomRightCorner.Rect.X - leftBorder.Rect.X; - - Assert.IsTrue(bottomRightCorner.Rect.Y >= topBorder.Rect.Y); - Assert.IsTrue(bottomRightCorner.Rect.X >= leftBorder.Rect.X); - Assert.IsTrue(actualHeight < expectedHeight); - Assert.IsTrue(actualWidth < expectedWidth); - - expectedHeight = actualHeight; - expectedWidth = actualWidth; - - //down-right - MoveCorner(bottomRightCorner, false, false, 5000, 5000); - actualHeight = bottomRightCorner.Rect.Y - topBorder.Rect.Y; - actualWidth = bottomRightCorner.Rect.X - leftBorder.Rect.X; - - Assert.IsTrue(bottomRightCorner.Rect.Y <= Screen.PrimaryScreen.WorkingArea.Bottom); - Assert.IsTrue(bottomRightCorner.Rect.X <= Screen.PrimaryScreen.WorkingArea.Right); - Assert.IsTrue(actualHeight > expectedHeight); - } - - [ClassInitialize] - public static void ClassInitialize(TestContext context) - { - Setup(context); - Assert.IsNotNull(session); - - EnableModules(false, true, false, false, false, false, false, false); - ResetSettings(); - - Assert.IsTrue(OpenEditor()); - OpenCustomLayouts(); - } - - [ClassCleanup] - public static void ClassCleanup() - { - CloseEditor(); - ExitPowerToys(); - TearDown(); - } - - [TestInitialize] - public void TestInitialize() - { - //create canvas zone - OpenCreatorWindow("Create new custom"); - creatorWindow.FindElementByAccessibilityId("newZoneButton").Click(); - } - - [TestCleanup] - public void TestCleanup() - { - AppiumWebElement cancelButton = creatorWindow.FindElementByName("Cancel"); - Assert.IsNotNull(cancelButton); - new Actions(session).MoveToElement(cancelButton).Click().Perform(); - } - } -} \ No newline at end of file diff --git a/src/tests/win-app-driver/FancyZonesTests/EditorCustomLayoutsTests.cs b/src/tests/win-app-driver/FancyZonesTests/EditorCustomLayoutsTests.cs deleted file mode 100644 index 1f75ba18a9..0000000000 --- a/src/tests/win-app-driver/FancyZonesTests/EditorCustomLayoutsTests.cs +++ /dev/null @@ -1,258 +0,0 @@ -using System.IO.Abstractions; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Newtonsoft.Json.Linq; -using OpenQA.Selenium; -using OpenQA.Selenium.Appium; -using OpenQA.Selenium.Appium.Windows; -using OpenQA.Selenium.Interactions; - -namespace PowerToysTests -{ - [TestClass] - public class FancyZonesEditorCustomLayoutsTests : FancyZonesEditor - { - private static readonly IFileSystem FileSystem = new FileSystem(); - private static readonly IFile File = FileSystem.File; - - private void SetLayoutName(string name) - { - AppiumWebElement textBox = creatorWindow.FindElementByClassName("TextBox"); - textBox.Click(); - textBox.SendKeys(Keys.Control + "a"); - textBox.SendKeys(Keys.Backspace); - textBox.SendKeys(name); - } - - private void CancelTest() - { - AppiumWebElement cancelButton = creatorWindow.FindElementByXPath("//Button[@Name=\"Cancel\"]"); - new Actions(session).MoveToElement(cancelButton).Click().Perform(); - WaitSeconds(1); - - Assert.AreEqual(_initialZoneSettings, File.ReadAllText(_zoneSettingsPath), "Settings were changed"); - } - - private void SaveTest(string type, string name, int zoneCount) - { - new Actions(session).MoveToElement(editorWindow.FindElementByName("Save and apply")).Click().Perform(); - WaitSeconds(1); - - JObject settings = JObject.Parse(File.ReadAllText(_zoneSettingsPath)); - Assert.AreEqual(name, settings["custom-zone-sets"][0]["name"]); - Assert.AreEqual(settings["custom-zone-sets"][0]["uuid"], settings["devices"][0]["active-zoneset"]["uuid"]); - Assert.AreEqual(type, settings["custom-zone-sets"][0]["type"]); - Assert.AreEqual(zoneCount, settings["custom-zone-sets"][0]["info"]["zones"].ToObject().Count); - } - - [TestMethod] - public void CreateCancel() - { - OpenCreatorWindow("Create new custom"); - ZoneCountTest(0, 0); - - editorWindow.FindElementByAccessibilityId("newZoneButton").Click(); - ZoneCountTest(1, 0); - - CancelTest(); - } - - [TestMethod] - public void CreateEmpty() - { - OpenCreatorWindow("Create new custom"); - ZoneCountTest(0, 0); - - SaveTest("canvas", "Custom Layout 1", 0); - } - - [TestMethod] - public void CreateSingleZone() - { - OpenCreatorWindow("Create new custom"); - ZoneCountTest(0, 0); - - editorWindow.FindElementByAccessibilityId("newZoneButton").Click(); - ZoneCountTest(1, 0); - - SaveTest("canvas", "Custom Layout 1", 1); - } - - [TestMethod] - public void CreateManyZones() - { - OpenCreatorWindow("Create new custom"); - ZoneCountTest(0, 0); - - const int expectedZoneCount = 20; - AppiumWebElement addButton = editorWindow.FindElementByAccessibilityId("newZoneButton"); - for (int i = 0; i < expectedZoneCount; i++) - { - addButton.Click(); - } - - ZoneCountTest(expectedZoneCount, 0); - SaveTest("canvas", "Custom Layout 1", expectedZoneCount); - } - - [TestMethod] - public void CreateDeleteZone() - { - OpenCreatorWindow("Create new custom"); - ZoneCountTest(0, 0); - - AppiumWebElement addButton = editorWindow.FindElementByAccessibilityId("newZoneButton"); - - for (int i = 0; i < 5; i++) - { - //add zone - addButton.Click(); - WindowsElement zone = session.FindElementByClassName("CanvasZone"); - Assert.IsNotNull(zone, "Zone was not created"); - Assert.IsTrue(zone.Displayed, "Zone was not displayed"); - - //remove zone - zone.FindElementByClassName("Button").Click(); - } - - ZoneCountTest(0, 0); - CancelTest(); - } - - [TestMethod] - public void CreateWithName() - { - OpenCreatorWindow("Create new custom"); - string name = "My custom zone layout name"; - SetLayoutName(name); - SaveTest("canvas", name, 0); - } - - [TestMethod] - public void CreateWithEmptyName() - { - OpenCreatorWindow("Create new custom"); - string name = ""; - SetLayoutName(name); - SaveTest("canvas", name, 0); - } - - [TestMethod] - public void CreateWithUnicodeCharactersName() - { - OpenCreatorWindow("Create new custom"); - string name = "ёÖ±¬āݾᵩὡ√ﮘﻹտ"; - SetLayoutName(name); - SaveTest("canvas", name, 0); - } - - [TestMethod] - public void RenameLayout() - { - //create layout - OpenCreatorWindow("Create new custom"); - string name = "My custom zone layout name"; - SetLayoutName(name); - SaveTest("canvas", name, 0); - WaitSeconds(1); - - //rename layout - Assert.IsTrue(OpenEditor()); - OpenCustomLayouts(); - OpenCreatorWindow(name); - name = "New name"; - SetLayoutName(name); - SaveTest("canvas", name, 0); - } - - [TestMethod] - public void AddRemoveSameLayoutNames() - { - string name = "Name"; - - for (int i = 0; i < 3; i++) - { - //create layout - OpenCreatorWindow("Create new custom"); - SetLayoutName(name); - - new Actions(session).MoveToElement(editorWindow.FindElementByName("Save and apply")).Click().Perform(); - - //remove layout - Assert.IsTrue(OpenEditor()); - OpenCustomLayouts(); - AppiumWebElement nameLabel = editorWindow.FindElementByXPath("//Text[@Name=\"" + name + "\"]"); - new Actions(session).MoveToElement(nameLabel).MoveByOffset(nameLabel.Rect.Width / 2 + 10, 0).Click().Perform(); - } - - //settings are saved on window closing - new Actions(session).MoveToElement(editorWindow.FindElementByAccessibilityId("PART_Close")).Click().Perform(); - WaitSeconds(1); - - //check settings - JObject settings = JObject.Parse(File.ReadAllText(_zoneSettingsPath)); - Assert.AreEqual(0, settings["custom-zone-sets"].ToObject().Count); - } - - [TestMethod] - public void RemoveApply() - { - string name = "Name"; - - //create layout - OpenCreatorWindow("Create new custom"); - SetLayoutName(name); - new Actions(session).MoveToElement(editorWindow.FindElementByName("Save and apply")).Click().Perform(); - WaitSeconds(1); - - //save layout id - JObject settings = JObject.Parse(File.ReadAllText(_zoneSettingsPath)); - Assert.AreEqual(1, settings["custom-zone-sets"].ToObject().Count); - - //remove layout - Assert.IsTrue(OpenEditor()); - OpenCustomLayouts(); - AppiumWebElement nameLabel = editorWindow.FindElementByXPath("//Text[@Name=\"" + name + "\"]"); - new Actions(session).MoveToElement(nameLabel).MoveByOffset(nameLabel.Rect.Width / 2 + 10, 0).Click().Perform(); - - //apply - new Actions(session).MoveToElement(editorWindow.FindElementByName("Apply")).Click().Perform(); - WaitSeconds(1); - - //check settings - settings = JObject.Parse(File.ReadAllText(_zoneSettingsPath)); - Assert.AreEqual(0, settings["custom-zone-sets"].ToObject().Count); - } - - [ClassInitialize] - public static void ClassInitialize(TestContext context) - { - Setup(context); - Assert.IsNotNull(session); - EnableModules(false, true, false, false, false, false, false, false); - - ResetDefaultFancyZonesSettings(false); - } - - [ClassCleanup] - public static void ClassCleanup() - { - ExitPowerToys(); - TearDown(); - } - - [TestInitialize] - public void TestInitialize() - { - ResetDefaultZoneSettings(true); - Assert.IsTrue(OpenEditor()); - OpenCustomLayouts(); - } - - [TestCleanup] - public void TestCleanup() - { - CloseEditor(); - ExitPowerToys(); - } - } -} \ No newline at end of file diff --git a/src/tests/win-app-driver/FancyZonesTests/EditorGridZoneResizeTests.cs b/src/tests/win-app-driver/FancyZonesTests/EditorGridZoneResizeTests.cs deleted file mode 100644 index 5a39a28423..0000000000 --- a/src/tests/win-app-driver/FancyZonesTests/EditorGridZoneResizeTests.cs +++ /dev/null @@ -1,438 +0,0 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using OpenQA.Selenium.Appium; -using OpenQA.Selenium.Appium.Windows; -using OpenQA.Selenium.Interactions; -using System; -using System.Collections.ObjectModel; -using System.Windows.Forms; - -namespace PowerToysTests -{ - [TestClass] - public class FancyZonesEditorGridZoneResizeTests : FancyZonesEditor - { - private const int moveStep = 5; - - private void Move(AppiumWebElement thumb, int border, bool moveAscending, bool moveHorizontally, int clickShift = 0) - { - Actions action = new Actions(session); - action.MoveToElement(thumb).MoveByOffset(0, clickShift).ClickAndHold(); - - int thumbCenter = 0; - if (moveHorizontally) - { - thumbCenter = thumb.Rect.X + thumb.Rect.Width / 2; - } - else - { - thumbCenter = thumb.Rect.Y + thumb.Rect.Height / 2; - } - - int moves = Math.Abs(thumbCenter - border) / moveStep; - for (int j = 0; j < moves; j++) - { - int step = moveAscending ? moveStep : -moveStep; - if (moveHorizontally) - { - action.MoveByOffset(step, 0); - } - else - { - action.MoveByOffset(0, step); - } - } - - action.Release().Perform(); - } - - [TestMethod] - public void MoveVerticalSplitter() - { - OpenCreatorWindow("Columns", "EditTemplateButton"); - WindowsElement gridEditor = session.FindElementByClassName("GridEditor"); - Assert.IsNotNull(gridEditor); - - Assert.AreEqual(3, gridEditor.FindElementsByClassName("GridZone").Count); - ReadOnlyCollection thumbs = gridEditor.FindElementsByClassName("Thumb"); - Assert.AreEqual(2, thumbs.Count); - - //move left - for (int i = 0; i < thumbs.Count; i++) - { - AppiumWebElement thumb = thumbs[i]; - int border = i == 0 ? 0 : thumbs[i - 1].Rect.Right; - Move(thumb, border, false, true); - - Assert.IsTrue(thumb.Rect.Left - border <= moveStep); - Assert.IsTrue(thumb.Rect.Right > border); - } - - //move right - for (int i = thumbs.Count - 1; i >= 0; i--) - { - AppiumWebElement thumb = thumbs[i]; - int border = i == thumbs.Count - 1 ? Screen.PrimaryScreen.WorkingArea.Right : thumbs[i + 1].Rect.Left; - Move(thumb, border, true, true); - - Assert.IsTrue(border - thumb.Rect.Right <= moveStep); - Assert.IsTrue(thumb.Rect.Left < border); - } - - //move up - foreach (AppiumWebElement thumb in thumbs) - { - int expected = thumb.Rect.X; - - Move(thumb, 0, false, false); - int actual = thumb.Rect.X; - - Assert.AreEqual(expected, actual); - } - - //move down - foreach (AppiumWebElement thumb in thumbs) - { - int expected = thumb.Rect.X; - - Move(thumb, Screen.PrimaryScreen.WorkingArea.Right, true, false); - int actual = thumb.Rect.X; - - Assert.AreEqual(expected, actual); - } - } - - [TestMethod] - public void MoveHorizontalSplitter() - { - OpenCreatorWindow("Rows", "EditTemplateButton"); - WindowsElement gridEditor = session.FindElementByClassName("GridEditor"); - Assert.IsNotNull(gridEditor); - - Assert.AreEqual(3, gridEditor.FindElementsByClassName("GridZone").Count); - ReadOnlyCollection thumbs = gridEditor.FindElementsByClassName("Thumb"); - Assert.AreEqual(2, thumbs.Count); - - //move up - for (int i = 0; i < thumbs.Count; i++) - { - AppiumWebElement thumb = thumbs[i]; - int border = i == 0 ? 0 : thumbs[i - 1].Rect.Bottom; - Move(thumb, border, false, false); - - Assert.IsTrue(thumb.Rect.Top - border <= moveStep); - Assert.IsTrue(thumb.Rect.Right > border); - } - - //move down - for (int i = thumbs.Count - 1; i >= 0; i--) - { - AppiumWebElement thumb = thumbs[i]; - int border = i == thumbs.Count - 1 ? Screen.PrimaryScreen.WorkingArea.Bottom : thumbs[i + 1].Rect.Top; - Move(thumb, border, true, false); - - Assert.IsTrue(border - thumb.Rect.Bottom <= moveStep); - Assert.IsTrue(thumb.Rect.Top < border); - } - - //move left - foreach (AppiumWebElement thumb in thumbs) - { - int expected = thumb.Rect.Y; - - Move(thumb, 0, false, true); - int actual = thumb.Rect.Y; - - Assert.AreEqual(expected, actual); - } - - //move right - foreach (AppiumWebElement thumb in thumbs) - { - int expected = thumb.Rect.Y; - - Move(thumb, Screen.PrimaryScreen.WorkingArea.Right, true, true); - int actual = thumb.Rect.Y; - - Assert.AreEqual(expected, actual); - } - } - - [TestMethod] - public void CreateSplitter() - { - OpenCreatorWindow("Columns", "EditTemplateButton"); - WindowsElement gridEditor = session.FindElementByClassName("GridEditor"); - Assert.IsNotNull(gridEditor); - - ReadOnlyCollection zones = gridEditor.FindElementsByClassName("GridZone"); - Assert.AreEqual(3, zones.Count, "Zones count invalid"); - - const int defaultSpacing = 16; - int splitPos = zones[0].Rect.Y + zones[0].Rect.Height / 2; - - new Actions(session).MoveToElement(zones[0]).Click().Perform(); - - zones = gridEditor.FindElementsByClassName("GridZone"); - Assert.AreEqual(4, zones.Count); - - //check splitted zone - Assert.AreEqual(defaultSpacing, zones[0].Rect.Top); - Assert.IsTrue(Math.Abs(zones[0].Rect.Bottom - splitPos + defaultSpacing / 2) <= 2); - Assert.IsTrue(Math.Abs(zones[1].Rect.Top - splitPos - defaultSpacing / 2) <= 2); - Assert.AreEqual(Screen.PrimaryScreen.Bounds.Bottom - defaultSpacing, zones[1].Rect.Bottom); - } - - [TestMethod] - public void TestSplitterShiftAfterCreation() - { - OpenCreatorWindow("Columns", "EditTemplateButton"); - WindowsElement gridEditor = session.FindElementByClassName("GridEditor"); - Assert.IsNotNull(gridEditor); - - ReadOnlyCollection zones = gridEditor.FindElementsByClassName("GridZone"); - Assert.AreEqual(3, zones.Count, "Zones count invalid"); - - const int defaultSpacing = 16; - - //create first split - int firstSplitPos = zones[0].Rect.Y + zones[0].Rect.Height / 4; - new Actions(session).MoveToElement(zones[0]).MoveByOffset(0, -(zones[0].Rect.Height / 4)).Click().Perform(); - - zones = gridEditor.FindElementsByClassName("GridZone"); - Assert.AreEqual(4, zones.Count); - - Assert.AreEqual(defaultSpacing, zones[0].Rect.Top); - Assert.IsTrue(Math.Abs(zones[0].Rect.Bottom - firstSplitPos + defaultSpacing / 2) <= 2); - Assert.IsTrue(Math.Abs(zones[1].Rect.Top - firstSplitPos - defaultSpacing / 2) <= 2); - Assert.AreEqual(Screen.PrimaryScreen.Bounds.Bottom - defaultSpacing, zones[3].Rect.Bottom); - - //create second split - int secondSplitPos = zones[3].Rect.Y + zones[3].Rect.Height / 2; - int expectedTop = zones[3].Rect.Top; - - new Actions(session).MoveToElement(zones[3]).Click().Perform(); - - zones = gridEditor.FindElementsByClassName("GridZone"); - Assert.AreEqual(5, zones.Count); - - //check first split on same position - Assert.AreEqual(defaultSpacing, zones[0].Rect.Top); - Assert.IsTrue(Math.Abs(zones[0].Rect.Bottom - firstSplitPos + defaultSpacing / 2) <= 2); - - //check second split - Assert.AreEqual(expectedTop, zones[3].Rect.Top); - Assert.IsTrue(Math.Abs(zones[3].Rect.Bottom - secondSplitPos + defaultSpacing / 2) <= 2); - Assert.IsTrue(Math.Abs(zones[4].Rect.Top - secondSplitPos - defaultSpacing / 2) <= 2); - Assert.AreEqual(Screen.PrimaryScreen.Bounds.Bottom - defaultSpacing, zones[4].Rect.Bottom); - } - - [TestMethod] - public void CreateSplitterWithShiftPressed() - { - OpenCreatorWindow("Columns", "EditTemplateButton"); - WindowsElement gridEditor = session.FindElementByClassName("GridEditor"); - Assert.IsNotNull(gridEditor); - - ReadOnlyCollection thumbs = gridEditor.FindElementsByClassName("Thumb"); - Assert.AreEqual(3, gridEditor.FindElementsByClassName("GridZone").Count); - Assert.AreEqual(2, thumbs.Count); - - new Actions(session).MoveToElement(thumbs[0]).Click().MoveByOffset(-100, 0) - .KeyDown(OpenQA.Selenium.Keys.Shift).Click().KeyUp(OpenQA.Selenium.Keys.Shift) - .Perform(); - Assert.AreEqual(3, gridEditor.FindElementsByClassName("Thumb").Count); - - ReadOnlyCollection zones = gridEditor.FindElementsByClassName("GridZone"); - Assert.AreEqual(4, zones.Count); - - //check that zone was splitted vertically - Assert.AreEqual(zones[0].Rect.Height, zones[1].Rect.Height); - Assert.AreEqual(zones[1].Rect.Height, zones[2].Rect.Height); - Assert.AreEqual(zones[2].Rect.Height, zones[3].Rect.Height); - } - - [TestMethod] - public void CreateSplitterWithShiftPressedFocusOnGridEditor() - { - OpenCreatorWindow("Columns", "EditTemplateButton"); - WindowsElement gridEditor = session.FindElementByClassName("GridEditor"); - Assert.IsNotNull(gridEditor); - - ReadOnlyCollection thumbs = gridEditor.FindElementsByClassName("Thumb"); - Assert.AreEqual(3, gridEditor.FindElementsByClassName("GridZone").Count); - Assert.AreEqual(2, thumbs.Count); - - new Actions(session).MoveToElement(thumbs[0]).Click().MoveByOffset(-100, 0) - .KeyDown(OpenQA.Selenium.Keys.Shift).Click().KeyUp(OpenQA.Selenium.Keys.Shift) - .Perform(); - Assert.AreEqual(3, gridEditor.FindElementsByClassName("Thumb").Count); - - ReadOnlyCollection zones = gridEditor.FindElementsByClassName("GridZone"); - Assert.AreEqual(4, zones.Count); - - //check that zone was splitted vertically - Assert.AreEqual(zones[0].Rect.Height, zones[1].Rect.Height); - Assert.AreEqual(zones[1].Rect.Height, zones[2].Rect.Height); - Assert.AreEqual(zones[2].Rect.Height, zones[3].Rect.Height); - } - - [TestMethod] - public void MoveHorizontallyWithLimiter() - { - OpenCreatorWindow("Columns", "EditTemplateButton"); - WindowsElement gridEditor = session.FindElementByClassName("GridEditor"); - Assert.IsNotNull(gridEditor); - - Assert.AreEqual(3, gridEditor.FindElementsByClassName("GridZone").Count); - ReadOnlyCollection thumbs = gridEditor.FindElementsByClassName("Thumb"); - Assert.AreEqual(2, thumbs.Count); - - //create new zones - new Actions(session).MoveToElement(thumbs[0]).Click().MoveByOffset(-30, 0) - .KeyDown(OpenQA.Selenium.Keys.Shift).Click().KeyUp(OpenQA.Selenium.Keys.Shift) - .Perform(); - thumbs = gridEditor.FindElementsByClassName("Thumb"); - Assert.AreEqual(4, gridEditor.FindElementsByClassName("GridZone").Count); - Assert.AreEqual(3, thumbs.Count); - - //move thumbs - AppiumWebElement limiter = gridEditor.FindElementsByClassName("Thumb")[0]; - AppiumWebElement movable = gridEditor.FindElementsByClassName("Thumb")[1]; - - Move(movable, 0, false, true); - Assert.IsTrue(movable.Rect.X > limiter.Rect.X); - Assert.IsTrue(movable.Rect.X - limiter.Rect.X < movable.Rect.Width); - - Move(limiter, limiter.Rect.X - (limiter.Rect.X / 2), false, true); - - Move(movable, 0, false, true); - Assert.IsTrue(movable.Rect.X > limiter.Rect.X); - Assert.IsTrue(movable.Rect.X - limiter.Rect.X < movable.Rect.Width); - } - - [TestMethod] - public void MoveVerticallyWithLimiter() - { - OpenCreatorWindow("Rows", "EditTemplateButton"); - WindowsElement gridEditor = session.FindElementByClassName("GridEditor"); - Assert.IsNotNull(gridEditor); - - Assert.AreEqual(3, gridEditor.FindElementsByClassName("GridZone").Count); - ReadOnlyCollection thumbs = gridEditor.FindElementsByClassName("Thumb"); - Assert.AreEqual(2, thumbs.Count); - - //create new zones - new Actions(session).MoveToElement(thumbs[0]).Click().MoveByOffset(0, -(thumbs[0].Rect.Y / 2)) - .KeyDown(OpenQA.Selenium.Keys.Shift).Click().KeyUp(OpenQA.Selenium.Keys.Shift) - .Perform(); - thumbs = gridEditor.FindElementsByClassName("Thumb"); - Assert.AreEqual(4, gridEditor.FindElementsByClassName("GridZone").Count); - Assert.AreEqual(3, thumbs.Count); - - //move thumbs - AppiumWebElement limiter = gridEditor.FindElementsByClassName("Thumb")[0]; - AppiumWebElement movable = gridEditor.FindElementsByClassName("Thumb")[1]; - - Move(movable, 0, false, false); - Assert.IsTrue(movable.Rect.Y > limiter.Rect.Y); - Assert.IsTrue(movable.Rect.Y - limiter.Rect.Y < movable.Rect.Height); - - Move(limiter, limiter.Rect.Y - (limiter.Rect.Y / 2), false, false, -5); - - Move(movable, 0, false, false); - Assert.IsTrue(movable.Rect.Y > limiter.Rect.Y); - Assert.IsTrue(movable.Rect.Y - limiter.Rect.Y < movable.Rect.Height); - } - - [TestMethod] - public void MergeZones() - { - OpenCreatorWindow("Columns", "EditTemplateButton"); - WindowsElement gridEditor = session.FindElementByClassName("GridEditor"); - Assert.IsNotNull(gridEditor); - - ReadOnlyCollection zones = gridEditor.FindElementsByClassName("GridZone"); - ReadOnlyCollection thumbs = gridEditor.FindElementsByClassName("Thumb"); - Assert.AreEqual(3, zones.Count); - Assert.AreEqual(2, thumbs.Count); - - Move(zones[0], thumbs[0].Rect.X + thumbs[0].Rect.Width + 10, true, true, -(zones[0].Rect.Height / 2) + 10); - - AppiumWebElement mergeButton = gridEditor.FindElementByName("Merge zones"); - Assert.IsNotNull(mergeButton, "Cannot merge: no merge button"); - new Actions(session).Click(mergeButton).Perform(); - - Assert.AreEqual(2, gridEditor.FindElementsByClassName("GridZone").Count); - Assert.AreEqual(1, gridEditor.FindElementsByClassName("Thumb").Count); - } - - [TestMethod] - public void MoveAfterMerge() - { - OpenCreatorWindow("Columns", "EditTemplateButton"); - WindowsElement gridEditor = session.FindElementByClassName("GridEditor"); - Assert.IsNotNull(gridEditor); - - ReadOnlyCollection thumbs = gridEditor.FindElementsByClassName("Thumb"); - - //create new zones - new Actions(session).MoveToElement(thumbs[0]).Click().MoveByOffset(-(thumbs[0].Rect.X / 2), 0) - .KeyDown(OpenQA.Selenium.Keys.Shift).Click().KeyUp(OpenQA.Selenium.Keys.Shift) - .Perform(); - thumbs = gridEditor.FindElementsByClassName("Thumb"); - - //merge zones - ReadOnlyCollection zones = gridEditor.FindElementsByClassName("GridZone"); - Move(zones[0], thumbs[0].Rect.X + thumbs[0].Rect.Width + 10, true, true, -(zones[0].Rect.Height / 2) + 10); - AppiumWebElement mergeButton = gridEditor.FindElementByName("Merge zones"); - Assert.IsNotNull(mergeButton, "Cannot merge: no merge button"); - new Actions(session).Click(mergeButton).Perform(); - - //move thumb - thumbs = gridEditor.FindElementsByClassName("Thumb"); - AppiumWebElement thumb = thumbs[0]; - Move(thumb, 0, false, true); - Assert.IsTrue(thumb.Rect.Left <= moveStep); - Assert.IsTrue(thumb.Rect.Right > 0); - } - - [ClassInitialize] - public static void ClassInitialize(TestContext context) - { - Setup(context); - Assert.IsNotNull(session); - EnableModules(false, true, false, false, false, false, false, false); - - ResetSettings(); - - if (!isPowerToysLaunched) - { - LaunchPowerToys(); - } - Assert.IsTrue(OpenEditor()); - OpenTemplates(); - } - - [ClassCleanup] - public static void ClassCleanup() - { - CloseEditor(); - ExitPowerToys(); - TearDown(); - } - - [TestInitialize] - public void TestInitialize() - { - - } - - [TestCleanup] - public void TestCleanup() - { - AppiumWebElement cancelButton = creatorWindow.FindElementByName("Cancel"); - Assert.IsNotNull(cancelButton); - new Actions(session).MoveToElement(cancelButton).Click().Perform(); - } - } -} \ No newline at end of file diff --git a/src/tests/win-app-driver/FancyZonesTests/EditorOpeningTests.cs b/src/tests/win-app-driver/FancyZonesTests/EditorOpeningTests.cs deleted file mode 100644 index dd762301e9..0000000000 --- a/src/tests/win-app-driver/FancyZonesTests/EditorOpeningTests.cs +++ /dev/null @@ -1,300 +0,0 @@ -using System.IO.Abstractions; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using OpenQA.Selenium.Appium; -using OpenQA.Selenium.Appium.Windows; -using OpenQA.Selenium.Interactions; - -namespace PowerToysTests -{ - [TestClass] - public class FancyZonesEditorOpeningTests : FancyZonesEditor - { - private static readonly IFileSystem FileSystem = new FileSystem(); - private static readonly IFile File = FileSystem.File; - private static readonly IDirectory Directory = FileSystem.Directory; - void RemoveSettingsFile() - { - File.Delete(_zoneSettingsPath); - File.Delete(_appHistoryPath); - } - - void RemoveSettingsFolder() - { - Directory.Delete(_settingsFolderPath, true); - } - - void CreateEmptySettingsFile() - { - string zoneSettings = ""; - File.WriteAllText(_zoneSettingsPath, zoneSettings); - - string appHistory = ""; - File.WriteAllText(_appHistoryPath, appHistory); - } - - void CreateDefaultSettingsFile() - { - string zoneSettings = "{\"devices\":[],\"custom-zone-sets\":[]}"; - File.WriteAllText(_zoneSettingsPath, zoneSettings); - - string appHistory = "{\"app-zone-history\":[]}"; - File.WriteAllText(_appHistoryPath, appHistory); - } - - void CreateValidSettingsFile() - { - string zoneSettings = "{\"devices\":[{\"device-id\":\"DELA026#5&10a58c63&0&UID16777488_1920_1200_{39B25DD2-130D-4B5D-8851-4791D66B1539}\",\"active-zoneset\":{\"uuid\":\"{D13ABB6D-7721-4176-9647-C8C0836D99CC}\",\"type\":\"columns\"},\"editor-show-spacing\":true,\"editor-spacing\":16,\"editor-zone-count\":3}],\"custom-zone-sets\":[]}"; - File.WriteAllText(_zoneSettingsPath, zoneSettings); - - string appHistory = "{\"app-zone-history\":[{\"app-path\":\"C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\Common7\\IDE\\Extensions\\TestPlatform\\testhost.exe\",\"zone-index\":3,\"device-id\":\"DELA026#5&10a58c63&0&UID16777488_1920_1200_{39B25DD2-130D-4B5D-8851-4791D66B1539}\",\"zoneset-uuid\":\"{D13ABB6D-7721-4176-9647-C8C0836D99CC}\"}]}"; - File.WriteAllText(_appHistoryPath, appHistory); - } - - void CreateValidSettingsFileWithUtf8() - { - string zoneSettings = "{\"devices\":[{\"device-id\":\"DELA026#5&10a58c63&0&UID16777488_1920_1200_{39B25DD2-130D-4B5D-8851-4791D66B1539}\",\"active-zoneset\":{\"uuid\":\"{D13ABB6D-7721-4176-9647-C8C0836D99CC}\",\"type\":\"columns\"},\"editor-show-spacing\":true,\"editor-spacing\":16,\"editor-zone-count\":3}],\"custom-zone-sets\":[]}"; - File.WriteAllText(_zoneSettingsPath, zoneSettings); - - string appHistory = "{\"app-zone-history\":[{\"app-path\":\"C:\\Program Files (x86)\\йцукен\\testhost.exe\",\"zone-index\":3,\"device-id\":\"DELA026#5&10a58c63&0&UID16777488_1920_1200_{39B25DD2-130D-4B5D-8851-4791D66B1539}\",\"zoneset-uuid\":\"{D13ABB6D-7721-4176-9647-C8C0836D99CC}\"}]}"; - File.WriteAllText(_appHistoryPath, appHistory); - } - - void CreateInvalidSettingsFile() - { - string zoneSettings = "{\"app-zone-history\":[{\"app-path\":\"C:\\Program Files (x86)\\Microsoft Visual Studio\\testhost.exe\",\"zone-index\":3,\"device-id\":\"wrong-device-id\",\"zoneset-uuid\":\"{D13ABB6D-invalid-uuid-C8C0836D99CC}\"}],\"devices\":[{\"device-id\":\"DELA026#5&10a58c63&0&UID16777488_1920_1200_{39B25DD2-130D-4B5D-8851-4791D66B1539}\",\"active-zoneset\":{\"uuid\":\"{D13ABB6D-7721-4176-9647-C8C0836D99CC}\",\"type\":\"columns\"},\"editor-show-spacing\":true,\"editor-spacing\":16,\"editor-zone-count\":3}],\"custom-zone-sets\":[]}"; - File.WriteAllText(_zoneSettingsPath, zoneSettings); - - string appHistory = ""; - File.WriteAllText(_appHistoryPath, appHistory); - } - - void CreateCroppedSettingsFile() - { - string zoneSettings = "{\"devices\":[],\"custom-zone-sets\":[{\"uuid\":\"{8BEC7183-C90E-4D41-AD1C-1AC2BC4760BA}\",\"name\":\""; - File.WriteAllText(_zoneSettingsPath, zoneSettings); - - string appHistory = "{\"app-zone-history\":[]}"; - File.WriteAllText(_appHistoryPath, appHistory); - } - - void TestEditorOpened(bool errorExpected = false) - { - WindowsElement errorMessage = null; - try - { - errorMessage = session.FindElementByName("FancyZones Editor Exception Handler"); - if (errorMessage != null) - { - errorMessage.FindElementByName("OK").Click(); - } - } - catch (OpenQA.Selenium.WebDriverException) - { - //no error message, it's ok - } - - editorWindow = session.FindElementByName("FancyZones Editor"); - Assert.IsNotNull(editorWindow); - - if (!errorExpected) - { - Assert.IsNull(errorMessage); - } - else - { - Assert.IsNotNull(errorMessage); - } - } - - void OpenEditorBySettingsButton() - { - OpenSettings(); - OpenFancyZonesSettings(); - settingsWindow.FindElementByName("Launch zones editor").Click(); - } - - void OpenEditorByHotkey() - { - new Actions(session).KeyDown(OpenQA.Selenium.Keys.Command).SendKeys("`").KeyUp(OpenQA.Selenium.Keys.Command).Perform(); - } - - [TestMethod] - public void OpenEditorBySettingsButtonNoSettings() - { - RemoveSettingsFile(); - OpenEditorBySettingsButton(); - TestEditorOpened(true); - } - - [TestMethod] - public void OpenEditorBySettingsButtonNoSettingsFolder() - { - /* - if (isPowerToysLaunched) - { - ExitPowerToys(); - } - RemoveSettingsFolder(); - LaunchPowerToys(); - */ - - RemoveSettingsFolder(); - OpenEditorBySettingsButton(); - TestEditorOpened(true); - } - - [TestMethod] - public void OpenEditorBySettingsButtonEmptySettings() - { - CreateEmptySettingsFile(); - OpenEditorBySettingsButton(); - TestEditorOpened(true); - } - - [TestMethod] - public void OpenEditorBySettingsButtonDefaultSettings() - { - CreateDefaultSettingsFile(); - OpenEditorBySettingsButton(); - TestEditorOpened(); - } - - [TestMethod] - public void OpenEditorBySettingsButtonValidSettings() - { - CreateValidSettingsFile(); - OpenEditorBySettingsButton(); - TestEditorOpened(); - } - - [TestMethod] - public void OpenEditorBySettingsButtonValidUtf8Settings() - { - CreateValidSettingsFileWithUtf8(); - OpenEditorBySettingsButton(); - TestEditorOpened(); - } - - [TestMethod] - public void OpenEditorBySettingsButtonInvalidSettings() - { - CreateInvalidSettingsFile(); - OpenEditorBySettingsButton(); - TestEditorOpened(true); - } - - [TestMethod] - public void OpenEditorBySettingsButtonCroppedSettings() - { - CreateCroppedSettingsFile(); - OpenEditorBySettingsButton(); - TestEditorOpened(true); - } - - [TestMethod] - public void OpenEditorByHotkeyNoSettings() - { - RemoveSettingsFile(); - OpenEditorByHotkey(); - TestEditorOpened(true); - } - - [TestMethod] - public void OpenEditorByHotkeyNoSettingsFolder() - { - /* - if (isPowerToysLaunched) - { - ExitPowerToys(); - } - RemoveSettingsFolder(); - LaunchPowerToys(); - */ - RemoveSettingsFolder(); - OpenEditorByHotkey(); - TestEditorOpened(true); - } - - [TestMethod] - public void OpenEditorByHotkeyEmptySettings() - { - CreateEmptySettingsFile(); - OpenEditorByHotkey(); - TestEditorOpened(true); - } - - [TestMethod] - public void OpenEditorByHotkeyDefaultSettings() - { - CreateDefaultSettingsFile(); - OpenEditorByHotkey(); - TestEditorOpened(); - } - - [TestMethod] - public void OpenEditorByHotkeyValidSettings() - { - CreateValidSettingsFile(); - OpenEditorByHotkey(); - TestEditorOpened(); - } - - [TestMethod] - public void OpenEditorByHotkeyValidUtf8Settings() - { - CreateValidSettingsFileWithUtf8(); - OpenEditorByHotkey(); - TestEditorOpened(); - } - - [TestMethod] - public void OpenEditorByHotkeyInvalidSettings() - { - CreateInvalidSettingsFile(); - OpenEditorByHotkey(); - TestEditorOpened(true); - } - - [TestMethod] - public void OpenEditorByHotkeyCroppedSettings() - { - CreateCroppedSettingsFile(); - OpenEditorByHotkey(); - TestEditorOpened(true); - } - - [ClassInitialize] - public static void ClassInitialize(TestContext context) - { - Setup(context); - Assert.IsNotNull(session); - EnableModules(false, true, false, false, false, false, false, false); - - ResetDefaultFancyZonesSettings(true); - } - - [ClassCleanup] - public static void ClassCleanup() - { - ExitPowerToys(); - TearDown(); - } - - [TestInitialize] - public void TestInitialize() - { - - } - - [TestCleanup] - public void TestCleanup() - { - CloseEditor(); - - if (!Directory.Exists(_settingsFolderPath)) - { - Directory.CreateDirectory(_settingsFolderPath); - } - } - } -} \ No newline at end of file diff --git a/src/tests/win-app-driver/FancyZonesTests/EditorSettingsTests.cs b/src/tests/win-app-driver/FancyZonesTests/EditorSettingsTests.cs deleted file mode 100644 index ca4c807469..0000000000 --- a/src/tests/win-app-driver/FancyZonesTests/EditorSettingsTests.cs +++ /dev/null @@ -1,206 +0,0 @@ -using System; -using System.IO.Abstractions; -//using System.IO; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Newtonsoft.Json.Linq; -using OpenQA.Selenium; -using OpenQA.Selenium.Appium; - -namespace PowerToysTests -{ - [TestClass] - public class FancyZonesEditorSettingsTests : FancyZonesEditor - { - private static readonly IFileSystem FileSystem = new FileSystem(); - private static readonly IFile File = FileSystem.File; - - private const string editorZoneCount = "editor-zone-count"; - private const string editorShowSpacing = "editor-show-spacing"; - private const string editorSpacing = "editor-spacing"; - - [TestMethod] - public void ZoneCount() - { - Assert.IsTrue(OpenEditor()); - - AppiumWebElement minusButton = editorWindow.FindElementByAccessibilityId("decrementZones"); - AppiumWebElement zoneCount = editorWindow.FindElementByAccessibilityId("zoneCount"); - - int editorZoneCountValue; - Assert.IsTrue(Int32.TryParse(zoneCount.Text, out editorZoneCountValue)); - - for (int i = editorZoneCountValue - 1, j = 0; i > -5; --i, ++j) - { - minusButton.Click(); - - Assert.IsTrue(Int32.TryParse(zoneCount.Text, out editorZoneCountValue)); - Assert.AreEqual(Math.Max(i, 1), editorZoneCountValue); - - if (j == 0 || i == -4) - { - editorWindow.FindElementByAccessibilityId("ApplyTemplateButton").Click(); - - WaitSeconds(1); - Assert.AreEqual(editorZoneCountValue, GetEditZonesSetting(editorZoneCount)); - Assert.IsTrue(OpenEditor()); - - minusButton = editorWindow.FindElementByAccessibilityId("decrementZones"); - zoneCount = editorWindow.FindElementByAccessibilityId("zoneCount"); - } - } - - AppiumWebElement plusButton = editorWindow.FindElementByAccessibilityId("incrementZones"); - - for (int i = 2; i < 45; ++i) - { - plusButton.Click(); - - Assert.IsTrue(Int32.TryParse(zoneCount.Text, out editorZoneCountValue)); - Assert.AreEqual(Math.Min(i, 40), editorZoneCountValue); - } - - editorWindow.FindElementByAccessibilityId("ApplyTemplateButton").Click(); - WaitSeconds(1); - Assert.AreEqual(editorZoneCountValue, GetEditZonesSetting(editorZoneCount)); - } - - [TestMethod] - public void ShowSpacingTest() - { - for (int i = 0; i < 2; ++i) - { - Assert.IsTrue(OpenEditor()); - - AppiumWebElement spaceAroundSetting = editorWindow.FindElementByAccessibilityId("spaceAroundSetting"); - bool spaceAroundSettingValue = spaceAroundSetting.Selected; - spaceAroundSetting.Click(); - - editorWindow.FindElementByAccessibilityId("ApplyTemplateButton").Click(); - - WaitSeconds(1); - - Assert.AreNotEqual(spaceAroundSettingValue, GetEditZonesSetting(editorShowSpacing)); - } - } - - [TestMethod] - public void SpacingTestsValid() - { - Assert.IsTrue(OpenEditor()); - - AppiumWebElement spaceAroundSetting = editorWindow.FindElementByAccessibilityId("spaceAroundSetting"); - bool editorShowSpacingValue = spaceAroundSetting.Selected; - - editorWindow.FindElementByAccessibilityId("ApplyTemplateButton").Click(); - - string[] validValues = { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" }; - - foreach (string editorSpacingValue in validValues) - { - Assert.IsTrue(OpenEditor()); - - AppiumWebElement paddingValue = editorWindow.FindElementByAccessibilityId("paddingValue"); - ClearText(paddingValue); - paddingValue.SendKeys(editorSpacingValue); - - editorWindow.FindElementByAccessibilityId("ApplyTemplateButton").Click(); - WaitSeconds(1); - - Assert.AreEqual(editorShowSpacingValue, GetEditZonesSetting(editorShowSpacing)); - Assert.AreEqual(editorSpacingValue, GetEditZonesSetting(editorSpacing)); - } - } - - [TestMethod] - public void SpacingTestsInvalid() - { - Assert.IsTrue(OpenEditor()); - - AppiumWebElement spaceAroundSetting = editorWindow.FindElementByAccessibilityId("spaceAroundSetting"); - bool editorShowSpacingValue = spaceAroundSetting.Selected; - - editorWindow.FindElementByAccessibilityId("ApplyTemplateButton").Click(); - - string[] invalidValues = { "!", "/", "<", "?", "D", "Z", "]", "m", "}", "1.5", "2,5" }; - - string editorSpacingValue = GetEditZonesSetting(editorSpacing); - - foreach (string value in invalidValues) - { - Assert.IsTrue(OpenEditor()); - - AppiumWebElement paddingValue = editorWindow.FindElementByAccessibilityId("paddingValue"); - ClearText(paddingValue); - paddingValue.SendKeys(value); - - editorWindow.FindElementByAccessibilityId("ApplyTemplateButton").Click(); - - Assert.AreEqual(editorShowSpacingValue, GetEditZonesSetting(editorShowSpacing)); - Assert.AreEqual(editorSpacingValue, GetEditZonesSetting(editorSpacing)); - } - } - - [TestMethod] - public void SpacingTestLargeValue() - { - Assert.IsTrue(OpenEditor()); - editorWindow.FindElementByName("Grid").Click(); - - AppiumWebElement paddingValue = editorWindow.FindElementByAccessibilityId("paddingValue"); - ClearText(paddingValue); - paddingValue.SendKeys("1000"); - - editorWindow.FindElementByAccessibilityId("ApplyTemplateButton").Click(); - editorWindow = null; - - try - { - Assert.IsTrue(OpenEditor()); - } - catch { } - - Assert.AreNotEqual(editorWindow, null, "Editor Zones Window is not starting after setting large padding value"); - } - - private T GetEditZonesSetting(string value) - { - JObject zoneSettings = JObject.Parse(File.ReadAllText(_zoneSettingsPath)); - T result = zoneSettings["devices"][0][value].ToObject(); - return result; - } - - private void ClearText(AppiumWebElement windowsElement) - { - windowsElement.SendKeys(Keys.Home); - windowsElement.SendKeys(Keys.Control + Keys.Delete); - } - - [ClassInitialize] - public static void ClassInitialize(TestContext context) - { - Setup(context); - Assert.IsNotNull(session); - EnableModules(false, true, false, false, false, false, false, false); - ResetSettings(); - } - - [ClassCleanup] - public static void ClassCleanup() - { - CloseSettings(); - ResetDefaultFancyZonesSettings(false); - ResetDefaultZoneSettings(false); - TearDown(); - } - - [TestInitialize] - public void TestInitialize() - { - } - - [TestCleanup] - public void TestCleanup() - { - } - } -} \ No newline at end of file diff --git a/src/tests/win-app-driver/FancyZonesTests/EditorTemplatesApplyTests.cs b/src/tests/win-app-driver/FancyZonesTests/EditorTemplatesApplyTests.cs deleted file mode 100644 index ace3aa3fc3..0000000000 --- a/src/tests/win-app-driver/FancyZonesTests/EditorTemplatesApplyTests.cs +++ /dev/null @@ -1,99 +0,0 @@ -using System.IO.Abstractions; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Newtonsoft.Json.Linq; - -namespace PowerToysTests -{ - [TestClass] - public class FancyZonesEditorTemplatesApplyTests : FancyZonesEditor - { - private static readonly IFileSystem FileSystem = new FileSystem(); - private static readonly IFile File = FileSystem.File; - - private void ApplyLayout(string tabName) - { - editorWindow.FindElementByName(tabName).Click(); - editorWindow.FindElementByAccessibilityId("ApplyTemplateButton").Click(); - - try - { - Assert.IsNull(session.FindElementByName("FancyZones Editor")); - } - catch (OpenQA.Selenium.WebDriverException) - { - //editor was closed as expected - } - } - - private void CheckSettingsLayout(string expectedLayout) - { - JObject settings = JObject.Parse(File.ReadAllText(_zoneSettingsPath)); - Assert.AreEqual(expectedLayout, settings["devices"][0]["active-zoneset"]["type"]); - } - - [TestMethod] - public void ApplyFocus() - { - ApplyLayout("Focus"); - CheckSettingsLayout("focus"); - } - - [TestMethod] - public void ApplyColumns() - { - ApplyLayout("Columns"); - CheckSettingsLayout("columns"); - } - - [TestMethod] - public void ApplyRows() - { - ApplyLayout("Rows"); - CheckSettingsLayout("rows"); - } - - [TestMethod] - public void ApplyGrid() - { - ApplyLayout("Grid"); - CheckSettingsLayout("grid"); - } - - [TestMethod] - public void ApplyPriorityGrid() - { - ApplyLayout("Priority Grid"); - CheckSettingsLayout("priority-grid"); - } - - [ClassInitialize] - public static void ClassInitialize(TestContext context) - { - Setup(context); - Assert.IsNotNull(session); - EnableModules(false, true, false, false, false, false, false, false); - - ResetDefaultFancyZonesSettings(true); - } - - [ClassCleanup] - public static void ClassCleanup() - { - CloseSettings(); - ExitPowerToys(); - TearDown(); - } - - [TestInitialize] - public void TestInitialize() - { - Assert.IsTrue(OpenEditor()); - OpenTemplates(); - } - - [TestCleanup] - public void TestCleanup() - { - } - } -} \ No newline at end of file diff --git a/src/tests/win-app-driver/FancyZonesTests/EditorTemplatesEditTests.cs b/src/tests/win-app-driver/FancyZonesTests/EditorTemplatesEditTests.cs deleted file mode 100644 index 6d1b922bb5..0000000000 --- a/src/tests/win-app-driver/FancyZonesTests/EditorTemplatesEditTests.cs +++ /dev/null @@ -1,207 +0,0 @@ -using System.IO.Abstractions; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Newtonsoft.Json.Linq; -using OpenQA.Selenium.Appium; -using OpenQA.Selenium.Interactions; - -namespace PowerToysTests -{ - [TestClass] - public class FancyZonesEditorTemplatesEditTests : FancyZonesEditor - { - private static readonly IFileSystem FileSystem = new FileSystem(); - private static readonly IFile File = FileSystem.File; - private void ChangeLayout() - { - new Actions(session).MoveToElement(creatorWindow.FindElementByAccessibilityId("PART_TitleBar")).MoveByOffset(0, -50).Click().Perform(); - } - - private void Cancel(AppiumWebElement creatorWindow) - { - AppiumWebElement cancelButton = creatorWindow.FindElementByName("Cancel"); - Assert.IsNotNull(cancelButton); - new Actions(session).MoveToElement(cancelButton).Click().Perform(); - } - - private void CancelTest(AppiumWebElement creatorWindow) - { - Cancel(creatorWindow); - WaitSeconds(1); - - Assert.AreEqual(_defaultZoneSettings, File.ReadAllText(_zoneSettingsPath), "Settings were changed"); - } - - private void SaveTest() - { - new Actions(session).MoveToElement(creatorWindow.FindElementByName("Save and apply")).Click().Perform(); - WaitSeconds(1); - - JObject settings = JObject.Parse(File.ReadAllText(_zoneSettingsPath)); - Assert.AreEqual("Custom Layout 1", settings["custom-zone-sets"][0]["name"]); - Assert.AreEqual(settings["custom-zone-sets"][0]["uuid"], settings["devices"][0]["active-zoneset"]["uuid"]); - } - - [TestMethod] - public void EditFocusCancel() - { - OpenCreatorWindow("Focus", "EditTemplateButton"); - ZoneCountTest(3, 0); - - creatorWindow.FindElementByAccessibilityId("newZoneButton").Click(); - ZoneCountTest(4, 0); - - CancelTest(creatorWindow); - } - - [TestMethod] - public void EditColumnsCancel() - { - OpenCreatorWindow("Columns", "EditTemplateButton"); - ZoneCountTest(0, 3); - - ChangeLayout(); - ZoneCountTest(0, 4); - - CancelTest(creatorWindow); - } - - [TestMethod] - public void EditRowsCancel() - { - OpenCreatorWindow("Rows", "EditTemplateButton"); - ZoneCountTest(0, 3); - - ChangeLayout(); - ZoneCountTest(0, 4); - - CancelTest(creatorWindow); - } - - [TestMethod] - public void EditGridCancel() - { - OpenCreatorWindow("Grid", "EditTemplateButton"); - ZoneCountTest(0, 3); - - ChangeLayout(); - ZoneCountTest(0, 4); - - CancelTest(creatorWindow); - } - - [TestMethod] - public void EditPriorityGridCancel() - { - OpenCreatorWindow("Priority Grid", "EditTemplateButton"); - ZoneCountTest(0, 3); - - ChangeLayout(); - ZoneCountTest(0, 4); - - CancelTest(creatorWindow); - } - - [TestMethod] - public void EditFocusSave() - { - OpenCreatorWindow("Focus", "EditTemplateButton"); - ZoneCountTest(3, 0); - - creatorWindow.FindElementByAccessibilityId("newZoneButton").Click(); - ZoneCountTest(4, 0); - - SaveTest(); - } - - [TestMethod] - public void EditColumnsSave() - { - OpenCreatorWindow("Columns", "EditTemplateButton"); - ZoneCountTest(0, 3); - - ChangeLayout(); - ZoneCountTest(0, 4); - - SaveTest(); - } - - [TestMethod] - public void EditRowsSave() - { - OpenCreatorWindow("Rows", "EditTemplateButton"); - ZoneCountTest(0, 3); - - ChangeLayout(); - ZoneCountTest(0, 4); - - SaveTest(); - } - - [TestMethod] - public void EditGridSave() - { - OpenCreatorWindow("Grid", "EditTemplateButton"); - ZoneCountTest(0, 3); - - ChangeLayout(); - ZoneCountTest(0, 4); - - SaveTest(); - } - - [TestMethod] - public void EditPriorityGridSave() - { - OpenCreatorWindow("Priority Grid", "EditTemplateButton"); - ZoneCountTest(0, 3); - - ChangeLayout(); - ZoneCountTest(0, 4); - - SaveTest(); - } - - [ClassInitialize] - public static void ClassInitialize(TestContext context) - { - Setup(context); - Assert.IsNotNull(session); - EnableModules(false, true, false, false, false, false, false, false); - - ResetDefaultFancyZonesSettings(false); - } - - [ClassCleanup] - public static void ClassCleanup() - { - CloseSettings(); - ExitPowerToys(); - TearDown(); - } - - [TestInitialize] - public void TestInitialize() - { - ResetDefaultZoneSettings(true); - Assert.IsTrue(OpenEditor()); - OpenTemplates(); - } - - [TestCleanup] - public void TestCleanup() - { - //Close editor - try - { - if (editorWindow != null) - { - editorWindow.SendKeys(OpenQA.Selenium.Keys.Alt + OpenQA.Selenium.Keys.F4); - } - } - catch (OpenQA.Selenium.WebDriverException) - { - //editor was already closed - } - } - } -} \ No newline at end of file diff --git a/src/tests/win-app-driver/FancyZonesTests/FancyZonesEditor.cs b/src/tests/win-app-driver/FancyZonesTests/FancyZonesEditor.cs deleted file mode 100644 index eaaa1dd19c..0000000000 --- a/src/tests/win-app-driver/FancyZonesTests/FancyZonesEditor.cs +++ /dev/null @@ -1,106 +0,0 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using OpenQA.Selenium.Appium; -using OpenQA.Selenium.Appium.Windows; -using OpenQA.Selenium.Interactions; -using System; - -namespace PowerToysTests -{ - public class FancyZonesEditor : PowerToysSession - { - protected static WindowsElement editorWindow; - protected static AppiumWebElement creatorWindow; - - protected static void ResetSettings() - { - ResetDefaultFancyZonesSettings(false); - ResetDefaultZoneSettings(true); - } - - protected static bool OpenEditor() - { - try - { - new Actions(session).KeyDown(OpenQA.Selenium.Keys.Command).SendKeys("`").KeyUp(OpenQA.Selenium.Keys.Command).Perform(); - - //editorWindow = WaitElementByXPath("//Window[@Name=\"FancyZones Editor\"]"); - editorWindow = session.FindElementByName("FancyZones Editor"); - Assert.IsNotNull(editorWindow, "Couldn't find editor window"); - - return true; - } - catch (Exception ex) - { - Console.WriteLine(ex.Message); - } - - return false; - } - - protected static void CloseEditor() - { - try - { - if (editorWindow != null) - { - editorWindow.SendKeys(OpenQA.Selenium.Keys.Alt + OpenQA.Selenium.Keys.F4); - } - } - catch (OpenQA.Selenium.WebDriverException) - { - //editor has been already closed - } - } - - protected static void OpenCustomLayouts() - { - try - { - WindowsElement customsTab = session.FindElementByName("Custom"); - customsTab.Click(); - string isSelected = customsTab.GetAttribute("SelectionItem.IsSelected"); - Assert.AreEqual("True", isSelected, "Custom tab cannot be opened"); - } - catch (Exception ex) - { - Console.WriteLine(ex.Message); - } - } - - protected static void OpenTemplates() - { - try - { - WindowsElement templatesTab = session.FindElementByName("Templates"); - templatesTab.Click(); - string isSelected = templatesTab.GetAttribute("SelectionItem.IsSelected"); - Assert.AreEqual("True", isSelected, "Templates tab cannot be opened"); - } - catch (Exception ex) - { - Console.WriteLine(ex.Message); - } - } - - protected static void OpenCreatorWindow(string tabName, string buttonId = "EditCustomButton") - { - try - { - editorWindow.FindElementByName(tabName).Click(); - editorWindow.FindElementByAccessibilityId(buttonId).Click(); - creatorWindow = editorWindow.FindElementByXPath("//Window"); - Assert.IsNotNull(creatorWindow, "Creator window didn't open"); - } - catch (Exception ex) - { - Console.WriteLine(ex.Message); - } - } - - protected void ZoneCountTest(int canvasZoneCount, int gridZoneCount) - { - Assert.AreEqual(canvasZoneCount, session.FindElementsByClassName("CanvasZone").Count); - Assert.AreEqual(gridZoneCount, session.FindElementsByClassName("GridZone").Count); - } - } -} \ No newline at end of file diff --git a/src/tests/win-app-driver/FancyZonesTests/FancyZonesSettingsTests.cs b/src/tests/win-app-driver/FancyZonesTests/FancyZonesSettingsTests.cs deleted file mode 100644 index 2c8ea49139..0000000000 --- a/src/tests/win-app-driver/FancyZonesTests/FancyZonesSettingsTests.cs +++ /dev/null @@ -1,776 +0,0 @@ -using System.Collections; -using System.Collections.Generic; -using System.Collections.ObjectModel; -using System.IO.Abstractions; -using System.Linq; -using System.Windows.Forms; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Newtonsoft.Json.Linq; -using OpenQA.Selenium.Appium; -using OpenQA.Selenium.Appium.Windows; -using OpenQA.Selenium.Interactions; - -namespace PowerToysTests -{ - [Ignore] - [TestClass] - public class FancyZonesSettingsTests : PowerToysSession - { - private static readonly IFileSystem FileSystem = new FileSystem(); - private static readonly IFile File = FileSystem.File; - - - private JObject _initialSettingsJson; - - private static WindowsElement _saveButton; - private static Actions _scrollUp; - - private const int _expectedTogglesCount = 9; - - private static void Init() - { - OpenSettings(); - OpenFancyZonesSettings(); - - _saveButton = session.FindElementByName("Save"); - Assert.IsNotNull(_saveButton); - - _scrollUp = new Actions(session).MoveToElement(_saveButton).MoveByOffset(0, _saveButton.Rect.Height).ContextClick() - .SendKeys(OpenQA.Selenium.Keys.Home); - Assert.IsNotNull(_scrollUp); - } - - private JObject GetProperties() - { - try - { - JObject settings = JObject.Parse(File.ReadAllText(_fancyZonesSettingsPath)); - return settings["properties"].ToObject(); - } - catch (Newtonsoft.Json.JsonReaderException) - { - return new JObject(); - } - } - - private T GetPropertyValue(string propertyName) - { - JObject properties = GetProperties(); - return properties[propertyName].ToObject()["value"].Value(); - } - - private T GetPropertyValue(JObject properties, string propertyName) - { - return properties[propertyName].ToObject()["value"].Value(); - } - - private void ScrollDown(int count) - { - Actions scroll = new Actions(session); - scroll.MoveToElement(_saveButton).MoveByOffset(0, _saveButton.Rect.Height).ContextClick(); - for (int i = 0; i < count; i++) - { - scroll.SendKeys(OpenQA.Selenium.Keys.PageDown); - } - - scroll.Perform(); - } - - private void ScrollUp() - { - _scrollUp.Perform(); - } - - private void SaveChanges() - { - string isEnabled = _saveButton.GetAttribute("IsEnabled"); - Assert.AreEqual("True", isEnabled); - - _saveButton.Click(); - - isEnabled = _saveButton.GetAttribute("IsEnabled"); - Assert.AreEqual("False", isEnabled); - } - - private void SaveAndCheckOpacitySettings(WindowsElement editor, int expected) - { - Assert.AreEqual(expected.ToString() + "\r\n", editor.Text); - - SaveChanges(); - WaitSeconds(1); - - int value = GetPropertyValue("fancyzones_highlight_opacity"); - Assert.AreEqual(expected, value); - } - - private void SetOpacity(WindowsElement editor, string key) - { - editor.Click(); //activate - editor.SendKeys(OpenQA.Selenium.Keys.Control + OpenQA.Selenium.Keys.Backspace); //clear previous value - editor.SendKeys(key); - editor.SendKeys(OpenQA.Selenium.Keys.Enter); //confirm changes - } - - private void TestRgbInput(string name) - { - WindowsElement colorInput = session.FindElementByXPath("//Edit[@Name=\"" + name + "\"]"); - Assert.IsNotNull(colorInput); - - colorInput.SendKeys(OpenQA.Selenium.Keys.Control + OpenQA.Selenium.Keys.Backspace); - colorInput.SendKeys("0"); - colorInput.SendKeys(OpenQA.Selenium.Keys.Enter); - Assert.AreEqual("0\r\n", colorInput.Text); - - string invalidSymbols = "qwertyuiopasdfghjklzxcvbnm,./';][{}:`~!@#$%^&*()_-+=\"\'\\"; - foreach (char symbol in invalidSymbols) - { - colorInput.SendKeys(symbol.ToString() + OpenQA.Selenium.Keys.Enter); - Assert.AreEqual("0\r\n", colorInput.Text); - } - - string validSymbols = "0123456789"; - foreach (char symbol in validSymbols) - { - colorInput.SendKeys(symbol.ToString() + OpenQA.Selenium.Keys.Enter); - Assert.AreEqual(symbol.ToString() + "\r\n", colorInput.Text); - colorInput.SendKeys(OpenQA.Selenium.Keys.Backspace); - } - - //print zero first - colorInput.SendKeys(OpenQA.Selenium.Keys.Control + OpenQA.Selenium.Keys.Backspace); - colorInput.SendKeys("0"); - colorInput.SendKeys("1"); - Assert.AreEqual("1\r\n", colorInput.Text); - - //too many symbols - colorInput.SendKeys(OpenQA.Selenium.Keys.Control + OpenQA.Selenium.Keys.Backspace); - colorInput.SendKeys("1"); - colorInput.SendKeys("2"); - colorInput.SendKeys("3"); - colorInput.SendKeys("4"); - Assert.AreEqual("123\r\n", colorInput.Text); - - //too big value - colorInput.SendKeys(OpenQA.Selenium.Keys.Control + OpenQA.Selenium.Keys.Backspace); - colorInput.SendKeys("555"); - - Actions action = new Actions(session); //reset focus from input - action.MoveToElement(colorInput).MoveByOffset(0, colorInput.Rect.Height).Click().Perform(); - - Assert.AreEqual("255\r\n", colorInput.Text); - } - - private void ClearInput(WindowsElement input) - { - input.Click(); - input.SendKeys(OpenQA.Selenium.Keys.Control + "a"); - input.SendKeys(OpenQA.Selenium.Keys.Backspace); - } - - private void TestHotkey(WindowsElement input, int modifierKeysState, string key, string keyString) - { - BitArray b = new BitArray(new int[] { modifierKeysState }); - int[] flags = b.Cast().Select(bit => bit ? 1 : 0).ToArray(); - - Actions action = new Actions(session).MoveToElement(input).Click(); - string expectedText = ""; - if (flags[0] == 1) - { - action.KeyDown(OpenQA.Selenium.Keys.Command); - expectedText += "Win + "; - } - if (flags[1] == 1) - { - action.KeyDown(OpenQA.Selenium.Keys.Control); - expectedText += "Ctrl + "; - } - if (flags[2] == 1) - { - action.KeyDown(OpenQA.Selenium.Keys.Alt); - expectedText += "Alt + "; - } - if (flags[3] == 1) - { - action.KeyDown(OpenQA.Selenium.Keys.Shift); - expectedText += "Shift + "; - } - - expectedText += keyString + "\r\n"; - - action.SendKeys(key + key); - action.MoveByOffset(0, (input.Rect.Height / 2) + 10).ContextClick(); - if (flags[0] == 1) - { - action.KeyUp(OpenQA.Selenium.Keys.Command); - } - if (flags[1] == 1) - { - action.KeyUp(OpenQA.Selenium.Keys.Control); - } - if (flags[2] == 1) - { - action.KeyUp(OpenQA.Selenium.Keys.Alt); - } - if (flags[3] == 1) - { - action.KeyUp(OpenQA.Selenium.Keys.Shift); - } - action.Perform(); - - SaveChanges(); - WaitSeconds(1); - - //Assert.AreEqual(expectedText, input.Text); - - JObject props = GetProperties(); - JObject hotkey = props["fancyzones_editor_hotkey"].ToObject()["value"].ToObject(); - Assert.AreEqual(flags[0] == 1, hotkey.Value("win")); - Assert.AreEqual(flags[1] == 1, hotkey.Value("ctrl")); - Assert.AreEqual(flags[2] == 1, hotkey.Value("alt")); - Assert.AreEqual(flags[3] == 1, hotkey.Value("shift")); - //Assert.AreEqual(keyString, hotkey.Value("key")); - } - - private void TestColorSliders(WindowsElement saturationAndBrightness, WindowsElement hue, WindowsElement hex, WindowsElement red, WindowsElement green, WindowsElement blue, string propertyName) - { - System.Drawing.Rectangle satRect = saturationAndBrightness.Rect; - System.Drawing.Rectangle hueRect = hue.Rect; - - //black on the bottom - new Actions(session).MoveToElement(saturationAndBrightness).ClickAndHold().MoveByOffset(0, satRect.Height).Release().Perform(); - WaitSeconds(1); - - Assert.AreEqual("0\r\n", red.Text); - Assert.AreEqual("0\r\n", green.Text); - Assert.AreEqual("0\r\n", blue.Text); - Assert.AreEqual("000000\r\n", hex.Text); - - SaveChanges(); - WaitSeconds(1); - Assert.AreEqual("#000000", GetPropertyValue(propertyName)); - - //white in left corner - new Actions(session).MoveToElement(saturationAndBrightness).ClickAndHold().MoveByOffset(-(satRect.Width / 2), -(satRect.Height / 2)).Release().Perform(); - Assert.AreEqual("255\r\n", red.Text); - Assert.AreEqual("255\r\n", green.Text); - Assert.AreEqual("255\r\n", blue.Text); - Assert.AreEqual("ffffff\r\n", hex.Text); - - SaveChanges(); - WaitSeconds(1); - Assert.AreEqual("#ffffff", GetPropertyValue(propertyName)); - - //color in right corner - new Actions(session).MoveToElement(saturationAndBrightness).ClickAndHold().MoveByOffset((satRect.Width / 2), -(satRect.Height / 2)).Release() - .MoveToElement(hue).ClickAndHold().MoveByOffset(-(hueRect.Width / 2), 0).Release().Perform(); - Assert.AreEqual("255\r\n", red.Text); - Assert.AreEqual("0\r\n", green.Text); - Assert.AreEqual("0\r\n", blue.Text); - Assert.AreEqual("ff0000\r\n", hex.Text); - - SaveChanges(); - WaitSeconds(1); - Assert.AreEqual("#ff0000", GetPropertyValue(propertyName)); - } - - [TestMethod] - public void FancyZonesSettingsOpen() - { - WindowsElement fzTitle = session.FindElementByName("FancyZones Settings"); - Assert.IsNotNull(fzTitle); - } - - /* - * click each toggle, - * save changes, - * check if settings are changed after clicking save button - */ - [TestMethod] - public void TogglesSingleClickSaveButtonTest() - { - List toggles = session.FindElementsByXPath("//Pane[@Name=\"PowerToys Settings\"]/*[@LocalizedControlType=\"toggleswitch\"]").ToList(); - Assert.AreEqual(_expectedTogglesCount, toggles.Count); - - List toggleValues = new List(); - foreach (WindowsElement toggle in toggles) - { - Assert.IsNotNull(toggle); - - bool isOn = toggle.GetAttribute("Toggle.ToggleState") == "1"; - toggleValues.Add(isOn); - - toggle.Click(); - - SaveChanges(); - } - - WaitSeconds(1); - - //check saved settings - JObject savedProps = GetProperties(); - Assert.AreNotEqual(toggleValues[0], GetPropertyValue(savedProps, "fancyzones_shiftDrag")); - Assert.AreNotEqual(toggleValues[1], GetPropertyValue(savedProps, "fancyzones_mouseSwitch")); - Assert.AreNotEqual(toggleValues[2], GetPropertyValue(savedProps, "fancyzones_overrideSnapHotkeys")); - Assert.AreNotEqual(toggleValues[3], GetPropertyValue(savedProps, "fancyzones_moveWindowAcrossMonitors")); - Assert.AreNotEqual(toggleValues[4], GetPropertyValue(savedProps, "fancyzones_moveWindowsBasedOnPosition")); - Assert.AreNotEqual(toggleValues[5], GetPropertyValue(savedProps, "fancyzones_displayChange_moveWindows")); - Assert.AreNotEqual(toggleValues[6], GetPropertyValue(savedProps, "fancyzones_zoneSetChange_moveWindows")); - Assert.AreNotEqual(toggleValues[7], GetPropertyValue(savedProps, "fancyzones_appLastZone_moveWindows")); - Assert.AreNotEqual(toggleValues[8], GetPropertyValue(savedProps, "fancyzones_restoreSize")); - Assert.AreNotEqual(toggleValues[9], GetPropertyValue(savedProps, "use_cursorpos_editor_startupscreen")); - Assert.AreNotEqual(toggleValues[10], GetPropertyValue(savedProps, "fancyzones_show_on_all_monitors")); - Assert.AreNotEqual(toggleValues[11], GetPropertyValue(savedProps, "fancyzones_multi_monitor_mode")); - Assert.AreNotEqual(toggleValues[12], GetPropertyValue(savedProps, "fancyzones_makeDraggedWindowTransparent")); - } - - /* - * click each toggle twice, - * save changes, - * check if settings are unchanged after clicking save button - */ - [TestMethod] - public void TogglesDoubleClickSave() - { - List toggles = session.FindElementsByXPath("//Pane[@Name=\"PowerToys Settings\"]/*[@LocalizedControlType=\"toggleswitch\"]").ToList(); - Assert.AreEqual(_expectedTogglesCount, toggles.Count); - - List toggleValues = new List(); - foreach (WindowsElement toggle in toggles) - { - Assert.IsNotNull(toggle); - - bool isOn = toggle.GetAttribute("Toggle.ToggleState") == "1"; - toggleValues.Add(isOn); - - toggle.Click(); - toggle.Click(); - } - - SaveChanges(); - WaitSeconds(1); - - JObject savedProps = GetProperties(); - Assert.AreEqual(toggleValues[0], GetPropertyValue(savedProps, "fancyzones_shiftDrag")); - Assert.AreEqual(toggleValues[1], GetPropertyValue(savedProps, "fancyzones_mouseSwitch")); - Assert.AreEqual(toggleValues[2], GetPropertyValue(savedProps, "fancyzones_overrideSnapHotkeys")); - Assert.AreEqual(toggleValues[3], GetPropertyValue(savedProps, "fancyzones_moveWindowAcrossMonitors")); - Assert.AreEqual(toggleValues[4], GetPropertyValue(savedProps, "fancyzones_moveWindowsBasedOnPosition")); - Assert.AreEqual(toggleValues[5], GetPropertyValue(savedProps, "fancyzones_displayChange_moveWindows")); - Assert.AreEqual(toggleValues[6], GetPropertyValue(savedProps, "fancyzones_zoneSetChange_moveWindows")); - Assert.AreEqual(toggleValues[7], GetPropertyValue(savedProps, "fancyzones_appLastZone_moveWindows")); - Assert.AreEqual(toggleValues[8], GetPropertyValue(savedProps, "fancyzones_restoreSize")); - Assert.AreEqual(toggleValues[9], GetPropertyValue(savedProps, "use_cursorpos_editor_startupscreen")); - Assert.AreEqual(toggleValues[10], GetPropertyValue(savedProps, "fancyzones_show_on_all_monitors")); - Assert.AreEqual(toggleValues[11], GetPropertyValue(savedProps, "fancyzones_span_zones_across_monitors")); - Assert.AreEqual(toggleValues[12], GetPropertyValue(savedProps, "fancyzones_makeDraggedWindowTransparent")); - } - - [TestMethod] - public void HighlightOpacitySetValue() - { - WindowsElement editor = session.FindElementByName("Zone opacity (%)"); - Assert.IsNotNull(editor); - - SetOpacity(editor, "50"); - SaveAndCheckOpacitySettings(editor, 50); - - SetOpacity(editor, "-50"); - SaveAndCheckOpacitySettings(editor, 0); - - SetOpacity(editor, "200"); - SaveAndCheckOpacitySettings(editor, 100); - - //for invalid input values previously saved value expected - SetOpacity(editor, "asdf"); - SaveAndCheckOpacitySettings(editor, 100); - - SetOpacity(editor, "*"); - SaveAndCheckOpacitySettings(editor, 100); - - SetOpacity(editor, OpenQA.Selenium.Keys.Return); - SaveAndCheckOpacitySettings(editor, 100); - - Clipboard.SetText("Hello, clipboard"); - SetOpacity(editor, OpenQA.Selenium.Keys.Control + "v"); - SaveAndCheckOpacitySettings(editor, 100); - } - - [TestMethod] - public void HighlightOpacityIncreaseValue() - { - WindowsElement editor = session.FindElementByName("Zone opacity (%)"); - Assert.IsNotNull(editor); - - SetOpacity(editor, "99"); - SaveAndCheckOpacitySettings(editor, 99); - - System.Drawing.Rectangle editorRect = editor.Rect; - - Actions action = new Actions(session); - action.MoveToElement(editor).MoveByOffset(editorRect.Width / 2 + 10, -editorRect.Height / 4).Perform(); - WaitSeconds(1); - - action.Click().Perform(); - Assert.AreEqual("100\r\n", editor.Text); - SaveAndCheckOpacitySettings(editor, 100); - - action.Click().Perform(); - Assert.AreEqual("100\r\n", editor.Text); - SaveAndCheckOpacitySettings(editor, 100); - } - - [TestMethod] - public void HighlightOpacityDecreaseValue() - { - - WindowsElement editor = session.FindElementByName("Zone opacity (%)"); - Assert.IsNotNull(editor); - - SetOpacity(editor, "1"); - SaveAndCheckOpacitySettings(editor, 1); - - System.Drawing.Rectangle editorRect = editor.Rect; - - Actions action = new Actions(session); - action.MoveToElement(editor).MoveByOffset(editorRect.Width / 2 + 10, editorRect.Height / 4).Perform(); - WaitSeconds(1); - - action.Click().Perform(); - Assert.AreEqual("0\r\n", editor.Text); - SaveAndCheckOpacitySettings(editor, 0); - - action.Click().Perform(); - Assert.AreEqual("0\r\n", editor.Text); - SaveAndCheckOpacitySettings(editor, 0); - } - - [TestMethod] - public void HighlightOpacityClearValueButton() - { - ScrollDown(3); - WindowsElement editor = session.FindElementByName("Zone opacity (%)"); - Assert.IsNotNull(editor); - - editor.Click(); //activate - AppiumWebElement clearButton = editor.FindElementByName("Clear value"); - Assert.IsNotNull(clearButton); - - /*element is not pointer- or keyboard interactable.*/ - Actions action = new Actions(session); - action.MoveToElement(clearButton).Click().Perform(); - - Assert.AreEqual("\r\n", editor.Text); - } - - [TestMethod] - public void HighlightColorSlidersTest() - { - ScrollDown(4); - - ReadOnlyCollection saturationAndBrightness = session.FindElementsByName("Saturation and brightness"); - ReadOnlyCollection hue = session.FindElementsByName("Hue"); - ReadOnlyCollection hex = session.FindElementsByXPath("//Edit[@Name=\"Hex\"]"); - ReadOnlyCollection red = session.FindElementsByXPath("//Edit[@Name=\"Red\"]"); - ReadOnlyCollection green = session.FindElementsByXPath("//Edit[@Name=\"Green\"]"); - ReadOnlyCollection blue = session.FindElementsByXPath("//Edit[@Name=\"Blue\"]"); - - TestColorSliders(saturationAndBrightness[2], hue[2], hex[2], red[2], green[2], blue[2], "fancyzones_zoneBorderColor"); - - new Actions(session).MoveToElement(saturationAndBrightness[2]).MoveByOffset(saturationAndBrightness[2].Rect.Width / 2 + 10, 0) - .Click().SendKeys(OpenQA.Selenium.Keys.PageUp).Perform(); - TestColorSliders(saturationAndBrightness[1], hue[1], hex[1], red[1], green[1], blue[1], "fancyzones_zoneColor"); - - new Actions(session).MoveToElement(saturationAndBrightness[1]).MoveByOffset(saturationAndBrightness[1].Rect.Width / 2 + 10, 0) - .Click().SendKeys(OpenQA.Selenium.Keys.PageDown + OpenQA.Selenium.Keys.PageDown).SendKeys(OpenQA.Selenium.Keys.PageUp + OpenQA.Selenium.Keys.PageUp).Perform(); - TestColorSliders(saturationAndBrightness[0], hue[0], hex[0], red[0], green[0], blue[0], "fancyzones_zoneHighlightColor"); - } - - [TestMethod] - public void HighlightColorTest() - { - ScrollDown(2); - - WindowsElement saturationAndBrightness = session.FindElementByName("Saturation and brightness"); - WindowsElement hue = session.FindElementByName("Hue"); - WindowsElement hex = session.FindElementByXPath("//Edit[@Name=\"Hex\"]"); - - Assert.IsNotNull(saturationAndBrightness); - Assert.IsNotNull(hue); - Assert.IsNotNull(hex); - - hex.SendKeys(OpenQA.Selenium.Keys.Control + OpenQA.Selenium.Keys.Backspace); - hex.SendKeys("63c99a"); - new Actions(session).MoveToElement(hex).MoveByOffset(0, hex.Rect.Height).Click().Perform(); - - Assert.AreEqual("Saturation 51 brightness 79", saturationAndBrightness.Text); - Assert.AreEqual("152", hue.Text); - - SaveChanges(); - WaitSeconds(1); - Assert.AreEqual("#63c99a", GetPropertyValue("fancyzones_zoneHighlightColor")); - } - - [TestMethod] - public void HighlightRGBInputsTest() - { - ScrollDown(2); - - TestRgbInput("Red"); - TestRgbInput("Green"); - TestRgbInput("Blue"); - } - - [TestMethod] - public void HighlightHexInputTest() - { - ScrollDown(2); - - WindowsElement hexInput = session.FindElementByXPath("//Edit[@Name=\"Hex\"]"); - Assert.IsNotNull(hexInput); - - hexInput.SendKeys(OpenQA.Selenium.Keys.Control + OpenQA.Selenium.Keys.Backspace); - - string invalidSymbols = "qwrtyuiopsghjklzxvnm,./';][{}:`~!#@$%^&*()_-+=\"\'\\"; - foreach (char symbol in invalidSymbols) - { - hexInput.SendKeys(symbol.ToString()); - Assert.AreEqual("", hexInput.Text.Trim()); - } - - string validSymbols = "0123456789abcdef"; - foreach (char symbol in validSymbols) - { - hexInput.SendKeys(symbol.ToString()); - Assert.AreEqual(symbol.ToString(), hexInput.Text.Trim()); - hexInput.SendKeys(OpenQA.Selenium.Keys.Backspace); - } - - //too many symbols - hexInput.SendKeys(OpenQA.Selenium.Keys.Control + OpenQA.Selenium.Keys.Backspace); - hexInput.SendKeys("000000"); - hexInput.SendKeys("1"); - Assert.AreEqual("000000\r\n", hexInput.Text); - - //short string - hexInput.SendKeys(OpenQA.Selenium.Keys.Control + OpenQA.Selenium.Keys.Backspace); - hexInput.SendKeys("000"); - new Actions(session).MoveToElement(hexInput).MoveByOffset(0, hexInput.Rect.Height).Click().Perform(); - Assert.AreEqual("000000\r\n", hexInput.Text); - - hexInput.SendKeys(OpenQA.Selenium.Keys.Control + OpenQA.Selenium.Keys.Backspace); - hexInput.SendKeys("1234"); - new Actions(session).MoveToElement(hexInput).MoveByOffset(0, hexInput.Rect.Height).Click().Perform(); - Assert.AreEqual("112233\r\n", hexInput.Text); - } - - [TestMethod] - public void ExcludeApps() - { - WindowsElement input = session.FindElementByXPath("//Edit[contains(@Name, \"exclude\")]"); - Assert.IsNotNull(input); - ClearInput(input); - - string inputValue; - - //valid - inputValue = "Notepad\nChrome"; - input.SendKeys(inputValue); - SaveChanges(); - ClearInput(input); - WaitSeconds(1); - Assert.AreEqual(inputValue, GetPropertyValue("fancyzones_excluded_apps")); - - //invalid - inputValue = "Notepad Chrome"; - input.SendKeys(inputValue); - SaveChanges(); - ClearInput(input); - WaitSeconds(1); - Assert.AreEqual(inputValue, GetPropertyValue("fancyzones_excluded_apps")); - - inputValue = "Notepad,Chrome"; - input.SendKeys(inputValue); - SaveChanges(); - ClearInput(input); - WaitSeconds(1); - Assert.AreEqual(inputValue, GetPropertyValue("fancyzones_excluded_apps")); - - inputValue = "Note*"; - input.SendKeys(inputValue); - SaveChanges(); - ClearInput(input); - WaitSeconds(1); - Assert.AreEqual(inputValue, GetPropertyValue("fancyzones_excluded_apps")); - - inputValue = "Кириллица"; - input.SendKeys(inputValue); - SaveChanges(); - ClearInput(input); - WaitSeconds(1); - Assert.AreEqual(inputValue, GetPropertyValue("fancyzones_excluded_apps")); - } - - [TestMethod] - public void ExitDialogSave() - { - WindowsElement toggle = session.FindElementByXPath("//Pane[@Name=\"PowerToys Settings\"]/*[@LocalizedControlType=\"toggleswitch\"]"); - Assert.IsNotNull(toggle); - - bool initialToggleValue = toggle.GetAttribute("Toggle.ToggleState") == "1"; - - toggle.Click(); - CloseSettings(); - WindowsElement exitDialog = session.FindElementByName("Changes not saved"); - Assert.IsNotNull(exitDialog); - - exitDialog.FindElementByName("Save").Click(); - - //check if window still opened - WindowsElement powerToysWindow = session.FindElementByXPath("//Window[@Name=\"PowerToys Settings\"]"); - Assert.IsNotNull(powerToysWindow); - - //check settings change - JObject savedProps = GetProperties(); - - Assert.AreNotEqual(initialToggleValue, GetPropertyValue(savedProps, "fancyzones_shiftDrag")); - - //return initial app state - toggle.Click(); - } - - [TestMethod] - public void ExitDialogExit() - { - WindowsElement toggle = session.FindElementByXPath("//Pane[@Name=\"PowerToys Settings\"]/*[@LocalizedControlType=\"toggleswitch\"]"); - Assert.IsNotNull(toggle); - - bool initialToggleValue = toggle.GetAttribute("Toggle.ToggleState") == "1"; - - toggle.Click(); - CloseSettings(); - - WindowsElement exitDialog = session.FindElementByName("Changes not saved"); - Assert.IsNotNull(exitDialog); - - exitDialog.FindElementByName("Exit").Click(); - - //check if window still opened - try - { - WindowsElement powerToysWindow = session.FindElementByXPath("//Window[@Name=\"PowerToys Settings\"]"); - Assert.IsNull(powerToysWindow); - } - catch (OpenQA.Selenium.WebDriverException) - { - //window is no longer available, which is expected - } - - //return initial app state - Init(); - - //check settings change - JObject savedProps = GetProperties(); - Assert.AreEqual(initialToggleValue, GetPropertyValue(savedProps, "fancyzones_shiftDrag")); - } - - [TestMethod] - public void ExitDialogCancel() - { - WindowsElement toggle = session.FindElementByXPath("//Pane[@Name=\"PowerToys Settings\"]/*[@LocalizedControlType=\"toggleswitch\"]"); - Assert.IsNotNull(toggle); - - toggle.Click(); - CloseSettings(); - WindowsElement exitDialog = session.FindElementByName("Changes not saved"); - Assert.IsNotNull(exitDialog); - - exitDialog.FindElementByName("Cancel").Click(); - - //check if window still opened - WindowsElement powerToysWindow = session.FindElementByXPath("//Window[@Name=\"PowerToys Settings\"]"); - Assert.IsNotNull(powerToysWindow); - - //check settings change - JObject savedProps = GetProperties(); - JObject initialProps = _initialSettingsJson["properties"].ToObject(); - Assert.AreEqual(GetPropertyValue(initialProps, "fancyzones_shiftDrag"), GetPropertyValue(savedProps, "fancyzones_shiftDrag")); - - //return initial app state - toggle.Click(); - SaveChanges(); - } - - [TestMethod] - public void ConfigureHotkey() - { - WindowsElement input = session.FindElementByXPath("//Edit[contains(@Name, \"hotkey\")]"); - Assert.IsNotNull(input); - - for (int i = 0; i < 16; i++) - { - TestHotkey(input, i, OpenQA.Selenium.Keys.End, "End"); - } - } - - [TestMethod] - public void ConfigureLocalSymbolHotkey() - { - WindowsElement input = session.FindElementByXPath("//Edit[contains(@Name, \"hotkey\")]"); - Assert.IsNotNull(input); - TestHotkey(input, 0, "ё", "Ё"); - } - - [ClassInitialize] - public static void ClassInitialize(TestContext context) - { - Setup(context); - Assert.IsNotNull(session); - - Init(); - } - - [ClassCleanup] - public static void ClassCleanup() - { - CloseSettings(); - - try - { - WindowsElement exitDialogButton = session.FindElementByName("Exit"); - if (exitDialogButton != null) - { - exitDialogButton.Click(); - } - } - catch (OpenQA.Selenium.WebDriverException) - { - //element couldn't be located - } - - ExitPowerToys(); - TearDown(); - } - - [TestInitialize] - public void TestInitialize() - { - if (session == null) - return; - - try - { - _initialSettingsJson = JObject.Parse(_initialFancyZonesSettings); - } - catch (Newtonsoft.Json.JsonReaderException) - { - //empty settings - } - } - - [TestCleanup] - public void TestCleanup() - { - ScrollUp(); - } - } -} diff --git a/src/tests/win-app-driver/FancyZonesTests/README.md b/src/tests/win-app-driver/FancyZonesTests/README.md deleted file mode 100644 index 57ac0514e4..0000000000 --- a/src/tests/win-app-driver/FancyZonesTests/README.md +++ /dev/null @@ -1,41 +0,0 @@ -# FancyZones Test Plan - -## Settings - - [x] Test if settings are saved in file properly - -## Editor - - [x] Open editor by clicking button from settings - - [x] without settings file - - [x] without settings folder - - [x] with valid settings file - - [x] with valid settings file contained cyrillic characters - - [x] with invalid settings file - - [x] with cropped file - - [x] Open editor by hotkey - - [x] without settings file - - [x] without settings folder - - [x] with valid settings file - - [x] with valid settings file contained cyrillic characters - - [x] with invalid settings file - - [x] with cropped file - - [ ] Increase/decrease zone count, check min and max possible values - - [ ] Test if settings are saved in file properly - - [ ] `Show spacing` checked/unchecked - - [ ] `Space around zone` saved correctly - - [ ] `Space around zone` possible input values - - [ ] Edit templates, check settings files - - [ ] Create new custom layout - - [ ] empty - - [ ] one zone - - [ ] fullscreen - - [ ] not fullscreen - - [ ] many zones - - [ ] overlapping - - [ ] non-overlapping - - [ ] utf-16 layout name - - [ ] empty layout name - - [ ] special characters in layout name - - [ ] Remove custom layout - - [ ] Edit selected layout - -### Usage diff --git a/src/tests/win-app-driver/PowerToysSession.cs b/src/tests/win-app-driver/PowerToysSession.cs deleted file mode 100644 index 479507e07f..0000000000 --- a/src/tests/win-app-driver/PowerToysSession.cs +++ /dev/null @@ -1,335 +0,0 @@ -using System; -using System.IO.Abstractions; -using System.Threading; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Newtonsoft.Json.Linq; -using OpenQA.Selenium; -using OpenQA.Selenium.Appium; -using OpenQA.Selenium.Appium.Windows; -using OpenQA.Selenium.Interactions; - -namespace PowerToysTests -{ - public class PowerToysSession - { - private static readonly IFileSystem FileSystem = new FileSystem(); - private static readonly IPath Path = FileSystem.Path; - private static readonly IFile File = FileSystem.File; - private static readonly IDirectory Directory = FileSystem.Directory; - - protected const string WindowsApplicationDriverUrl = "http://127.0.0.1:4723"; - protected const string AppPath = "C:\\Program Files\\PowerToys\\PowerToys.exe"; - - protected static WindowsDriver session; - protected static bool isPowerToysLaunched = false; - - protected static WindowsElement trayButton; - protected static WindowsElement settingsWindow; - - protected static string _commonSettingsFolderPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Microsoft\\PowerToys"); - protected static string _settingsFolderPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Microsoft\\PowerToys\\FancyZones"); - protected static string _fancyZonesSettingsPath = _settingsFolderPath + "\\settings.json"; - protected static string _zoneSettingsPath = _settingsFolderPath + "\\zones-settings.json"; - protected static string _appHistoryPath = _settingsFolderPath + "\\app-zone-history.json"; - protected static string _commonSettingsPath = _commonSettingsFolderPath + "\\settings.json"; - - protected static string _initialFancyZonesSettings = ""; - protected static string _initialZoneSettings = ""; - protected static string _initialAppHistorySettings = ""; - protected static string _initialCommonSettings = ""; - - protected const string _defaultFancyZonesSettings = "{\"version\":\"1.0\",\"name\":\"FancyZones\",\"properties\":{\"fancyzones_shiftDrag\":{\"value\":true},\"fancyzones_mouseSwitch\":{\"value\":false},\"fancyzones_overrideSnapHotkeys\":{\"value\":false},\"fancyzones_moveWindowAcrossMonitors\":{\"value\":false},\"fancyzones_zoneSetChange_flashZones\":{\"value\":false},\"fancyzones_displayChange_moveWindows\":{\"value\":false},\"fancyzones_zoneSetChange_moveWindows\":{\"value\":false},\"fancyzones_appLastZone_moveWindows\":{\"value\":false},\"use_cursorpos_editor_startupscreen\":{\"value\":true},\"fancyzones_zoneHighlightColor\":{\"value\":\"#0078D7\"},\"fancyzones_highlight_opacity\":{\"value\":90},\"fancyzones_editor_hotkey\":{\"value\":{\"win\":true,\"ctrl\":false,\"alt\":false,\"shift\":false,\"code\":192,\"key\":\"`\"}},\"fancyzones_excluded_apps\":{\"value\":\"\"}}}"; - protected const string _defaultZoneSettings = "{\"devices\":[],\"custom-zone-sets\":[]}"; - - - public static void Setup(TestContext context) - { - if (session == null) - { - ReadUserSettings(); //read settings before running tests to restore them after - - // Create a new Desktop session to use PowerToys. - AppiumOptions appiumOptions = new AppiumOptions(); - appiumOptions.PlatformName = "Windows"; - appiumOptions.AddAdditionalCapability("app", "Root"); - try - { - session = new WindowsDriver(new Uri(WindowsApplicationDriverUrl), appiumOptions); - session.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(1); - - trayButton = session.FindElementByAccessibilityId("1502"); - - isPowerToysLaunched = CheckPowerToysLaunched(); - } - catch (Exception ex) - { - Console.WriteLine(ex.Message); - } - } - } - - public static void TearDown() - { - RestoreUserSettings(); //restore initial settings files - - if (session != null) - { - trayButton = null; - settingsWindow = null; - - session.Quit(); - session = null; - } - } - - public static void WaitSeconds(double seconds) - { - Thread.Sleep(TimeSpan.FromSeconds(seconds)); - } - - public static void OpenSettings() - { - trayButton.Click(); - - try - { - PowerToysTrayButton().Click(); - settingsWindow = session.FindElementByName("PowerToys Settings"); - } - catch (Exception ex) - { - Console.WriteLine(ex.Message); - } - - trayButton.Click(); //close - Assert.IsNotNull(settingsWindow); - } - - public static void OpenFancyZonesSettings() - { - try - { - AppiumWebElement fzNavigationButton = settingsWindow.FindElementByName("FancyZones"); - Assert.IsNotNull(fzNavigationButton); - - fzNavigationButton.Click(); - } - catch (Exception ex) - { - Console.WriteLine(ex.Message); - } - } - - public static void CloseSettings() - { - try - { - WindowsElement settings = session.FindElementByName("PowerToys Settings"); - if (settings != null) - { - settings.Click(); - settings.FindElementByName("Close").Click(); - //settings.SendKeys(Keys.Alt + Keys.F4); - } - } - catch (Exception ex) - { - Console.WriteLine(ex.Message); - } - } - - protected static AppiumWebElement PowerToysTrayButton() - { - WindowsElement notificationOverflow = session.FindElementByName("Notification Overflow"); - AppiumWebElement overflowArea = notificationOverflow.FindElementByName("Overflow Notification Area"); - AppiumWebElement powerToys = overflowArea.FindElementByXPath("//Button[contains(@Name, \"PowerToys\")]"); - return powerToys; - } - - private static bool CheckPowerToysLaunched() - { - bool isLaunched = false; - trayButton.Click(); - - try - { - AppiumWebElement pt = PowerToysTrayButton(); - isLaunched = (pt != null); - } - catch (OpenQA.Selenium.WebDriverException) - { - //PowerToys not found - } - - trayButton.Click(); //close - return isLaunched; - } - - public static void LaunchPowerToys() - { - AppiumOptions opts = new AppiumOptions(); - opts.AddAdditionalCapability("app", AppPath); - - try - { - WindowsDriver driver = new WindowsDriver(new Uri(WindowsApplicationDriverUrl), opts); - Assert.IsNotNull(driver); - driver.LaunchApp(); - } - catch (WebDriverException) - { - //exception is expected since WinApDriver tries to find main app window - } - - isPowerToysLaunched = true; - } - - public static void ExitPowerToys() - { - trayButton.Click(); - - try - { - AppiumWebElement pt = PowerToysTrayButton(); - Assert.IsNotNull(pt, "Could not exit PowerToys"); - - new Actions(session).MoveToElement(pt).ContextClick().Perform(); - session.FindElementByAccessibilityId("40001").Click(); - //WaitElementByXPath("//MenuItem[@Name=\"Exit\"]").Click(); - - isPowerToysLaunched = false; - } - catch (Exception ex) - { - Console.WriteLine(ex.Message); - } - - trayButton.Click(); //close tray - } - - public static void EnableModules(bool colorPicker, bool fancyZones, bool fileExplorer, bool imageResizer, bool keyboardManager, bool powerRename, bool powerRun, bool shortcutGuide, bool relaunch = false) - { - JObject json = JObject.Parse(_initialCommonSettings); - JObject enabled = new JObject(); - enabled["ColorPicker"] = colorPicker; - enabled["FancyZones"] = fancyZones; - enabled["File Explorer"] = fileExplorer; - enabled["Image Resizer"] = imageResizer; - enabled["Keyboard Manager"] = keyboardManager; - enabled["PowerRename"] = powerRename; - enabled["PowerToys Run"] = powerRun; - enabled["Shortcut Guide"] = shortcutGuide; - - json["enabled"] = enabled; - - ResetSettings(_commonSettingsFolderPath, _commonSettingsPath, json.ToString(), relaunch); - } - - public static void ResetDefaultFancyZonesSettings(bool relaunch) - { - ResetSettings(_settingsFolderPath, _fancyZonesSettingsPath, _defaultFancyZonesSettings, relaunch); - } - - public static void ResetDefaultZoneSettings(bool relaunch) - { - ResetSettings(_settingsFolderPath, _zoneSettingsPath, _defaultZoneSettings, relaunch); - } - - private static void ResetSettings(string folder, string filePath, string data, bool relaunch) - { - if (!Directory.Exists(folder)) - { - Directory.CreateDirectory(folder); - } - File.WriteAllText(filePath, data); - - ExitPowerToys(); - if (relaunch) - { - LaunchPowerToys(); - } - } - - private static void ReadUserSettings() - { - try - { - if (_initialCommonSettings.Length == 0) - { - _initialCommonSettings = File.ReadAllText(_commonSettingsPath); - } - } - catch (Exception) - { } - - try - { - if (_initialFancyZonesSettings.Length == 0) - { - _initialFancyZonesSettings = File.ReadAllText(_fancyZonesSettingsPath); - } - } - catch (Exception) - { } - - try - { - if (_initialZoneSettings.Length == 0) - { - _initialZoneSettings = File.ReadAllText(_zoneSettingsPath); - } - } - catch (Exception) - { } - - try - { - if (_initialAppHistorySettings.Length == 0) - { - _initialAppHistorySettings = File.ReadAllText(_appHistoryPath); - } - } - catch (Exception) - { } - } - - private static void RestoreUserSettings() - { - if (_initialCommonSettings.Length > 0) - { - File.WriteAllText(_commonSettingsPath, _initialCommonSettings); - } - else - { - File.Delete(_commonSettingsPath); - } - - if (_initialFancyZonesSettings.Length > 0) - { - File.WriteAllText(_fancyZonesSettingsPath, _initialFancyZonesSettings); - } - else - { - File.Delete(_fancyZonesSettingsPath); - } - - if (_initialZoneSettings.Length > 0) - { - File.WriteAllText(_zoneSettingsPath, _initialZoneSettings); - } - else - { - File.Delete(_zoneSettingsPath); - } - - if (_initialAppHistorySettings.Length > 0) - { - File.WriteAllText(_appHistoryPath, _initialAppHistorySettings); - } - else - { - File.Delete(_appHistoryPath); - } - } - } -} diff --git a/src/tests/win-app-driver/PowerToysTrayTests.cs b/src/tests/win-app-driver/PowerToysTrayTests.cs deleted file mode 100644 index a55739cabd..0000000000 --- a/src/tests/win-app-driver/PowerToysTrayTests.cs +++ /dev/null @@ -1,121 +0,0 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using OpenQA.Selenium.Appium; -using OpenQA.Selenium.Appium.Windows; -using OpenQA.Selenium.Interactions; - -namespace PowerToysTests -{ - [TestClass] - public class PowerToysTrayTests : PowerToysSession - { - private bool isSettingsOpened; - private bool isTrayOpened; - - [TestMethod] - public void SettingsOpen() - { - OpenSettings(); - - //check settings window opened - WindowsElement settingsWindow = session.FindElementByName("PowerToys Settings"); - Assert.IsNotNull(settingsWindow); - - isSettingsOpened = true; - } - - [TestMethod] - public void SettingsOpenWithContextMenu() - { - //open tray - trayButton.Click(); - WaitSeconds(1); - isTrayOpened = true; - - //open PowerToys context menu - AppiumWebElement pt = PowerToysTrayButton(); - Assert.IsNotNull(pt); - - new Actions(session).MoveToElement(pt).ContextClick().Perform(); - - //open settings - session.FindElementByXPath("//MenuItem[@Name=\"Settings\"]").Click(); - - //check settings window opened - WindowsElement settingsWindow = session.FindElementByName("PowerToys Settings"); - Assert.IsNotNull(settingsWindow); - - isSettingsOpened = true; - } - - [TestMethod] - public void PowerToysExit() - { - //open PowerToys context menu - trayButton.Click(); - isTrayOpened = true; - WaitSeconds(1); - - AppiumWebElement powerToys = PowerToysTrayButton(); - Assert.IsNotNull(powerToys); - - new Actions(session).MoveToElement(powerToys).ContextClick().Perform(); - - //exit - session.FindElementByAccessibilityId("40001").Click(); - - //check PowerToys exited - powerToys = null; - try - { - powerToys = PowerToysTrayButton(); - } - catch (OpenQA.Selenium.WebDriverException) - { - //expected, PowerToys shouldn't be here - } - - LaunchPowerToys(); - Assert.IsNull(powerToys); - } - - [ClassInitialize] - public static void ClassInitialize(TestContext context) - { - Setup(context); - Assert.IsNotNull(session); - - if (!isPowerToysLaunched) - { - LaunchPowerToys(); - } - } - - [ClassCleanup] - public static void ClassCleanup() - { - ExitPowerToys(); - TearDown(); - } - - [TestInitialize] - public void TestInitialize() - { - isSettingsOpened = false; - isTrayOpened = false; - } - - [TestCleanup] - public void TestCleanup() - { - if (isSettingsOpened) - { - CloseSettings(); - } - - if (isTrayOpened) - { - trayButton.Click(); - } - } - } -} diff --git a/src/tests/win-app-driver/README.md b/src/tests/win-app-driver/README.md deleted file mode 100644 index dfa5d882f5..0000000000 --- a/src/tests/win-app-driver/README.md +++ /dev/null @@ -1,81 +0,0 @@ -# PowerToys Tests - -The PowerToys tests are implemented using Appium and use the [Windows Application Driver](https://github.com/microsoft/WinAppDriver) as an Appium compatible server for Windows applications. - -## Prerequisites - - Install the latest stable version of Windows Application Driver in the test machine: [v1.1 Release](https://github.com/microsoft/WinAppDriver/releases/tag/v1.1) - - Install the ".Net desktop development" components in Visual Studio 2019. It should have support for `C#` and `.Net Framework 4.7.2`. - - Install [PowerToys](https://github.com/microsoft/PowerToys/releases/) - - In Windows 10 Settings, turn on `Developer Mode` (open the Windows 10 Settings and search "Developer settings"). - -If you have `PowerToys` installed, it can be launched automatically. Otherwise, if you are testing a local build, you should start `PowerToys` before running the tests. - -### Preparing the test machine - - Start `PowerToys` if necessary (see the Prerequisites). - - Run `WinAppDriver.exe` in Administrator mode, on the test machine. By default it's installed in `C:\Program Files (x86)\Windows Application Driver\` - - **Note:** notifications or other application windows, that are shown above the PowerToys settings window or tray icon, can disrupt the testing process. - -When testing on a remote machine, a Firewall exceptions must be added and the IP and port must be passed when starting "Windows Application Driver". Here's how to do it from the [Windows Application Driver FAQ](https://github.com/microsoft/WinAppDriver/wiki/Frequently-Asked-Questions#running-on-a-remote-machine): - -#### Running on a Remote Machine - -Windows Application Driver can run remotely on any Windows 10 machine with `WinAppDriver.exe` installed and running. This *test machine* can then serve any JSON wire protocol commands coming from the *test runner* remotely through the network. Below are the steps to the one-time setup for the *test machine* to receive inbound requests: - -1. On the *test machine* you want to run the test application on, open up **Windows Firewall with Advanced Security** - - Select **Inbound Rules** -> **New Rule...** - - **Rule Type** -> **Port** - - Select **TCP** - - Choose specific local port (4723 is WinAppDriver standard) - - **Action** -> **Allow the connection** - - **Profile** -> select all - - **Name** -> optional, choose name for rule (e.g. WinAppDriver remote). - - Below command when run in admin command prompt gives same result - ```shell - netsh advfirewall firewall add rule name="WinAppDriver remote" dir=in action=allow protocol=TCP localport=4723 - ``` - -2. Run `ipconfig.exe` to determine your machine's local IP address - > **Note**: Setting `*` as the IP address command line option will cause it to bind to all bound IP addresses on the machine -3. Run `WinAppDriver.exe 10.X.X.10 4723/wd/hub` as **administrator** with command line arguments as seen above specifying local IP and port -4. On the *test runner* machine where the runner and scripts are, update the test script to point to the IP of the remote *test machine* - -### Starting the tests on the Development Machine - - Open `PowerToys.sln` in Visual Studio. - - Build the `PowerToysTests` project. - - Select `Test > Windows > Test Explorer`. - - Select `Test > Run > All` tests in the menu bar. - -> Once the project is successfully built, you can use the **TestExplorer** to pick and choose the test scenario(s) to run - -> If Visual Studio fail to discover and run the test scenarios: -> 1. Select **Tools** > **Options...** > **Test** -> 2. Under *Active Solution*, uncheck *For improved performance, only use test adapters in test assembly folder or as specified in runsettings file* - -If a remote test machine is being used, the IP of the test machine must be used to replace the `WindowsApplicationDriverUrl` value in [PowerToysSession.cs](PowerToysSession.cs). - -### Extra tools and information - -For tests creation you will need a tool that enables you select any UI element and view the element's accessibility data. For this purpose you could use [AccessibilityInsights](https://accessibilityinsights.io/docs/windows/overview) or [Inspect](https://learn.microsoft.com/windows/win32/winauto/inspect-objects?redirectedfrom=MSDN). - -* `inspect.exe` you can find installed at `C:\Program Files (x86)\Windows Kits\10\bin\\\inspect.exe` -* `AccessibilityInsights` you can download [here](https://aka.ms/accessibilityinsights-windows/download) - -##### How to use Inspect -Open Inspect, find element you need to investigate (by clicking on element or finding it in a tree) and in the right part of inspector window you will see info about this element. - -Examples for searching elements with values of `Name`, `AutomationId` and `ControlType`: -``` -//use FindElementByAccessibilityId with AutomationId value -session.FindElementByAccessibilityId("40001"); -session.FindElementByAccessibilityId("decrementZones"); - -session.FindElementByName("PowerToys Settings"); - -//with XPath you can search elements with more specific information -session.FindElementByXPath("//Pane[@Name=\"PowerToys Settings\"]"); -session.FindElementByXPath("//Edit[contains(@Name, \"hotkey\")]"); -session.FindElementByXPath("//Pane[@Name=\"PowerToys Settings\"]/*[@LocalizedControlType=\"toggleswitch\"]"); -``` - ->One more thing to notice: close helper tools while running tests. Overlapping windows can affect test results. diff --git a/src/tests/win-app-driver/TestShortcutGuideHelper.cs b/src/tests/win-app-driver/TestShortcutGuideHelper.cs deleted file mode 100644 index 17067e93f0..0000000000 --- a/src/tests/win-app-driver/TestShortcutGuideHelper.cs +++ /dev/null @@ -1,166 +0,0 @@ -using System; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using OpenQA.Selenium.Appium; -using OpenQA.Selenium.Appium.Windows; -using OpenQA.Selenium.Interactions; - -namespace PowerToysTests -{ - [TestClass] - public class TestShortcutGuideHelper : PowerToysSession - { - // Try to manage Press/Release of Windows Key here, - // since Keyboard.PressKey seems to release the key if pressed - // and Keyboard.ReleaseKey seems to press the key if not pressed. - private bool isWinKeyPressed; - - private void PressWinKey() - { - if (!isWinKeyPressed) - { - new Actions(session).KeyDown(OpenQA.Selenium.Keys.Command).Perform(); - isWinKeyPressed = true; - } - } - - private void ReleaseWinKey() - { - if (isWinKeyPressed) - { - new Actions(session).KeyUp(OpenQA.Selenium.Keys.Command).Perform(); - isWinKeyPressed = false; - } - } - - [TestMethod] - public void AppearsOnWinKeyPress() - { - PressWinKey(); - WaitSeconds(3); - - try - { - WindowsElement shortcutHelperWindow = session.FindElementByXPath("/Pane[@ClassName=\"#32769\"]/Pane[@ClassName=\"PToyD2DPopup\"]"); - Assert.IsNotNull(shortcutHelperWindow); - } - catch(OpenQA.Selenium.WebDriverException) - { - Assert.Fail("Shortcut Guide not found"); - } - } - - [TestMethod] - [ExpectedException(typeof(InvalidOperationException), - "The Shortcut Guide UI was still found after releasing the key.")] - public void DisappearsOnWinKeyRelease() - { - PressWinKey(); - WaitSeconds(2); - WindowsElement shortcutHelperWindow; - try - { - shortcutHelperWindow = session.FindElementByXPath("/Pane[@ClassName=\"#32769\"]/Pane[@ClassName=\"PToyD2DPopup\"]"); - Assert.IsNotNull(shortcutHelperWindow); - } - catch (InvalidOperationException) - { - // Not the exception we wanted to catch here. - Assert.Fail("Shortcut Guide not found"); - } - - ReleaseWinKey(); - shortcutHelperWindow = session.FindElementByXPath("/Pane[@ClassName=\"#32769\"]/Pane[@ClassName=\"PToyD2DPopup\"]"); - Assert.IsNull(shortcutHelperWindow); - } - - [TestMethod] - public void DoesNotBlockStartMenuOnShortPress() - { - PressWinKey(); - WaitSeconds(0.4); - // FindElementByClassName will be faster than using with XPath. - WindowsElement shortcutHelperWindow = session.FindElementByClassName("PToyD2DPopup"); - Assert.IsNotNull(shortcutHelperWindow); - ReleaseWinKey(); - WindowsElement startMenuWindow = session.FindElementByXPath("/Pane[@ClassName=\"#32769\"]/Window[@Name=\"Start\"]"); - } - [TestMethod] - [ExpectedException(typeof(InvalidOperationException), - "The Start Menu was found after releasing the key on a long press.")] - public void DoesNotSpawnStartMenuOnLongPress() - { - PressWinKey(); - WaitSeconds(2); - try - { - // FindElementByClassName will be faster than using with XPath. - WindowsElement shortcutHelperWindow = session.FindElementByClassName("PToyD2DPopup"); - Assert.IsNotNull(shortcutHelperWindow); - } - catch (InvalidOperationException) - { - // Not the exception we wanted to catch here. - Assert.Fail("Shortcut Guide not found"); - } - ReleaseWinKey(); - WindowsElement startMenuWindow = session.FindElementByXPath("/Pane[@ClassName=\"#32769\"]/Window[@Name=\"Start\"]"); - } - - [ClassInitialize] - public static void ClassInitialize(TestContext context) - { - Setup(context); - Assert.IsNotNull(session); - EnableModules(false, false, false, false, false, false, false, true); - - if (!isPowerToysLaunched) - { - LaunchPowerToys(); - } - } - - [ClassCleanup] - public static void ClassCleanup() - { - ExitPowerToys(); - TearDown(); - } - - [TestInitialize] - public void TestInitialize() - { - isWinKeyPressed = false; - - // If the start menu is open, close it. - WindowsElement startMenuWindow = null; - try - { - startMenuWindow = session.FindElementByXPath("/Pane[@ClassName=\"#32769\"]/Window[@Name=\"Start\"]"); - } - catch (Exception) - { - //Start menu not found, as expected. - } - if (startMenuWindow != null) - { - string startMenuWindowHandle = (int.Parse(startMenuWindow.GetAttribute("NativeWindowHandle"))).ToString("x"); - // Create session for controlling the Start Menu. - AppiumOptions appiumOptions = new AppiumOptions(); - appiumOptions.PlatformName = "Windows"; - appiumOptions.AddAdditionalCapability("appTopLevelWindow", startMenuWindowHandle); - WindowsDriver startMenuSession = new WindowsDriver(new Uri(WindowsApplicationDriverUrl), appiumOptions); - if (startMenuSession != null) - { - new Actions(session).SendKeys(OpenQA.Selenium.Keys.Escape + OpenQA.Selenium.Keys.Escape).Perform(); - startMenuSession.Quit(); - } - } - } - [TestCleanup] - public void TestCleanup() - { - // Release Windows Key in case it's being pressed by some of the tests - ReleaseWinKey(); - } - } -} diff --git a/src/tests/win-app-driver/win-app-driver.csproj b/src/tests/win-app-driver/win-app-driver.csproj deleted file mode 100644 index 5694111928..0000000000 --- a/src/tests/win-app-driver/win-app-driver.csproj +++ /dev/null @@ -1,21 +0,0 @@ - - - - netcoreapp3.1 - PowerToysTests - false - true - - - - - - - - - - - - - -