diff --git a/src/tests/win-app-driver/FancyZonesTests/EditorCanvasZoneResizeTests.cs b/src/tests/win-app-driver/FancyZonesTests/EditorCanvasZoneResizeTests.cs index 955e6abb8a..f43b329f07 100644 --- a/src/tests/win-app-driver/FancyZonesTests/EditorCanvasZoneResizeTests.cs +++ b/src/tests/win-app-driver/FancyZonesTests/EditorCanvasZoneResizeTests.cs @@ -26,13 +26,18 @@ namespace PowerToysTests 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] @@ -43,13 +48,18 @@ namespace PowerToysTests 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] @@ -60,13 +70,18 @@ namespace PowerToysTests 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] @@ -77,13 +92,18 @@ namespace PowerToysTests 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(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] @@ -96,41 +116,32 @@ namespace PowerToysTests Assert.IsNotNull(bottomBorder); Assert.IsNotNull(rightBorder); - //up - MoveCorner(topLeftCorner, true, true, 0, -5000); - Assert.IsTrue(topLeftCorner.Rect.Y >= 0); - - //down - MoveCorner(topLeftCorner, true, true, 0, 5000); - Assert.IsTrue(topLeftCorner.Rect.Y <= bottomBorder.Rect.Y); + 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); - //up-right - MoveCorner(topLeftCorner, true, true, 5000, -5000); - Assert.IsTrue(topLeftCorner.Rect.Y >= 0); - Assert.IsTrue(topLeftCorner.Rect.X <= rightBorder.Rect.X); - - //to the left - MoveCorner(topLeftCorner, true, true, -5000, 0); - Assert.IsTrue(topLeftCorner.Rect.X >= 0); - - //to the right - MoveCorner(topLeftCorner, true, true, 5000, 0); - Assert.IsTrue(topLeftCorner.Rect.X <= rightBorder.Rect.X); - - //down-left - MoveCorner(topLeftCorner, true, true, -5000, 5000); - Assert.IsTrue(topLeftCorner.Rect.Y <= bottomBorder.Rect.Y); - Assert.IsTrue(topLeftCorner.Rect.X >= 0); + 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] @@ -143,41 +154,32 @@ namespace PowerToysTests Assert.IsNotNull(bottomBorder); Assert.IsNotNull(leftBorder); - //up - MoveCorner(topRightCorner, false, true, 0, -5000); - Assert.IsTrue(topRightCorner.Rect.Y >= 0); - - //down - MoveCorner(topRightCorner, false, true, 0, 5000); - Assert.IsTrue(topRightCorner.Rect.Y <= bottomBorder.Rect.Y); - - //up-left - MoveCorner(topRightCorner, false, true, -5000, -5000); - Assert.IsTrue(topRightCorner.Rect.Y >= 0); - Assert.IsTrue(topRightCorner.Rect.X >= leftBorder.Rect.X); + 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); - //to the left - MoveCorner(topRightCorner, false, true, -5000, 0); - Assert.IsTrue(topRightCorner.Rect.X >= leftBorder.Rect.X); - - //to the right - MoveCorner(topRightCorner, false, true, 5000, 0); - Assert.IsTrue(leftBorder.Rect.X <= Screen.PrimaryScreen.WorkingArea.Right); - - //down-right - MoveCorner(topRightCorner, false, true, 5000, 5000); - Assert.IsTrue(topRightCorner.Rect.Y <= bottomBorder.Rect.Y); - Assert.IsTrue(leftBorder.Rect.X <= Screen.PrimaryScreen.WorkingArea.Right); + 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] @@ -190,41 +192,32 @@ namespace PowerToysTests Assert.IsNotNull(topBorder); Assert.IsNotNull(rightBorder); - //down - MoveCorner(bottomLeftCorner, true, false, 0, 5000); - Assert.IsTrue(bottomLeftCorner.Rect.Y <= Screen.PrimaryScreen.WorkingArea.Bottom); - - //up - MoveCorner(bottomLeftCorner, true, false, 0, -5000); - Assert.IsTrue(bottomLeftCorner.Rect.Y >= topBorder.Rect.Y); - - //down-right - MoveCorner(bottomLeftCorner, true, false, 5000, 5000); - Assert.IsTrue(bottomLeftCorner.Rect.Y <= Screen.PrimaryScreen.WorkingArea.Bottom); - Assert.IsTrue(bottomLeftCorner.Rect.X <= rightBorder.Rect.X); - - //down-left - MoveCorner(bottomLeftCorner, true, false, -5000, 5000); - Assert.IsTrue(bottomLeftCorner.Rect.Y <= Screen.PrimaryScreen.WorkingArea.Bottom); - Assert.IsTrue(bottomLeftCorner.Rect.X >= 0); - - //to the right - MoveCorner(bottomLeftCorner, true, false, 5000, 0); - Assert.IsTrue(bottomLeftCorner.Rect.X <= rightBorder.Rect.X); - - //to the left - MoveCorner(bottomLeftCorner, true, false, -5000, 0); - Assert.IsTrue(bottomLeftCorner.Rect.X >= 0); + 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); - Assert.IsTrue(bottomLeftCorner.Rect.Y >= topBorder.Rect.Y); - Assert.IsTrue(bottomLeftCorner.Rect.X >= 0); - - //up-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 >= 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] @@ -237,41 +230,31 @@ namespace PowerToysTests Assert.IsNotNull(topBorder); Assert.IsNotNull(leftBorder); - //to the right - MoveCorner(bottomRightCorner, false, false, 5000, 0); - Assert.IsTrue(bottomRightCorner.Rect.X <= Screen.PrimaryScreen.WorkingArea.Right); - - //to the left - MoveCorner(bottomRightCorner, false, false, -5000, 0); - Assert.IsTrue(bottomRightCorner.Rect.X >= leftBorder.Rect.X); - - //down - MoveCorner(bottomRightCorner, false, false, 0, 5000); - Assert.IsTrue(bottomRightCorner.Rect.Y <= Screen.PrimaryScreen.WorkingArea.Bottom); - - //up - MoveCorner(bottomRightCorner, false, false, 0, -5000); - Assert.IsTrue(bottomRightCorner.Rect.Y >= topBorder.Rect.Y); + 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); - //up-right - MoveCorner(bottomRightCorner, false, false, 5000, -5000); - Assert.IsTrue(bottomRightCorner.Rect.Y >= topBorder.Rect.Y); - Assert.IsTrue(bottomRightCorner.Rect.X <= Screen.PrimaryScreen.WorkingArea.Right); + 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); - - //down-left - MoveCorner(bottomRightCorner, false, false, -5000, 5000); - Assert.IsTrue(bottomRightCorner.Rect.Y <= Screen.PrimaryScreen.WorkingArea.Bottom); - Assert.IsTrue(bottomRightCorner.Rect.X >= leftBorder.Rect.X); + Assert.IsTrue(actualHeight > expectedHeight); } [ClassInitialize] @@ -285,17 +268,12 @@ namespace PowerToysTests LaunchPowerToys(); } OpenEditor(); - OpenCustomLayouts(); - - //create canvas zone - OpenCreatorWindow("Create new custom", "Custom layout creator"); - session.FindElementByAccessibilityId("newZoneButton").Click(); + OpenCustomLayouts(); } [ClassCleanup] public static void ClassCleanup() { - new Actions(session).MoveToElement(session.FindElementByXPath("//Button[@Name=\"Cancel\"]")).Click().Perform(); CloseEditor(); TearDown(); } @@ -303,13 +281,15 @@ namespace PowerToysTests [TestInitialize] public void TestInitialize() { - + //create canvas zone + OpenCreatorWindow("Create new custom", "Custom layout creator"); + session.FindElementByAccessibilityId("newZoneButton").Click(); } [TestCleanup] public void TestCleanup() { - + new Actions(session).MoveToElement(session.FindElementByXPath("//Button[@Name=\"Cancel\"]")).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 index 49b184c8cc..3e2927e295 100644 --- a/src/tests/win-app-driver/FancyZonesTests/EditorCustomLayoutsTests.cs +++ b/src/tests/win-app-driver/FancyZonesTests/EditorCustomLayoutsTests.cs @@ -23,7 +23,7 @@ namespace PowerToysTests { WindowsElement cancelButton = session.FindElementByXPath("//Window[@Name=\"FancyZones Editor\"]/Window/Button[@Name=\"Cancel\"]"); new Actions(session).MoveToElement(cancelButton).Click().Perform(); - ShortWait(); + WaitSeconds(1); Assert.AreEqual(_initialZoneSettings, File.ReadAllText(_zoneSettingsPath), "Settings were changed"); } @@ -31,7 +31,7 @@ namespace PowerToysTests private void SaveTest(string type, string name, int zoneCount) { new Actions(session).MoveToElement(session.FindElementByName("Save and apply")).Click().Perform(); - ShortWait(); + WaitSeconds(1); JObject settings = JObject.Parse(File.ReadAllText(_zoneSettingsPath)); Assert.AreEqual(name, settings["custom-zone-sets"][0]["name"]); @@ -149,7 +149,7 @@ namespace PowerToysTests string name = "My custom zone layout name"; SetLayoutName(name); SaveTest("canvas", name, 0); - ShortWait(); + WaitSeconds(1); //rename layout OpenEditor(); @@ -168,7 +168,7 @@ namespace PowerToysTests string name = "Name"; SetLayoutName(name); SaveTest("canvas", name, 0); - ShortWait(); + WaitSeconds(1); //save layout id JObject settings = JObject.Parse(File.ReadAllText(_zoneSettingsPath)); @@ -183,7 +183,7 @@ namespace PowerToysTests //settings are saved on window closing new Actions(session).MoveToElement(session.FindElementByAccessibilityId("PART_Close")).Click().Perform(); - ShortWait(); + WaitSeconds(1); //check settings settings = JObject.Parse(File.ReadAllText(_zoneSettingsPath)); @@ -206,7 +206,7 @@ namespace PowerToysTests SetLayoutName(name); new Actions(session).MoveToElement(session.FindElementByName("Save and apply")).Click().Perform(); - ShortWait(); + WaitSeconds(1); //remove layout OpenEditor(); @@ -217,7 +217,7 @@ namespace PowerToysTests //settings are saved on window closing new Actions(session).MoveToElement(session.FindElementByAccessibilityId("PART_Close")).Click().Perform(); - ShortWait(); + WaitSeconds(1); //check settings JObject settings = JObject.Parse(File.ReadAllText(_zoneSettingsPath)); @@ -236,8 +236,7 @@ namespace PowerToysTests SetLayoutName(name); new Actions(session).MoveToElement(session.FindElementByName("Save and apply")).Click().Perform(); - ShortWait(); - + //remove layout OpenEditor(); OpenCustomLayouts(); @@ -247,7 +246,7 @@ namespace PowerToysTests //settings are saved on window closing new Actions(session).MoveToElement(session.FindElementByAccessibilityId("PART_Close")).Click().Perform(); - ShortWait(); + WaitSeconds(1); //check settings JObject settings = JObject.Parse(File.ReadAllText(_zoneSettingsPath)); @@ -263,7 +262,7 @@ namespace PowerToysTests OpenCreatorWindow("Create new custom", "Custom layout creator"); SetLayoutName(name); new Actions(session).MoveToElement(session.FindElementByName("Save and apply")).Click().Perform(); - ShortWait(); + WaitSeconds(1); //save layout id JObject settings = JObject.Parse(File.ReadAllText(_zoneSettingsPath)); @@ -278,7 +277,7 @@ namespace PowerToysTests //apply new Actions(session).MoveToElement(session.FindElementByName("Apply")).Click().Perform(); - ShortWait(); + WaitSeconds(1); //check settings settings = JObject.Parse(File.ReadAllText(_zoneSettingsPath)); diff --git a/src/tests/win-app-driver/FancyZonesTests/EditorOpeningTests.cs b/src/tests/win-app-driver/FancyZonesTests/EditorOpeningTests.cs index 62bb3cccee..b9f4866841 100644 --- a/src/tests/win-app-driver/FancyZonesTests/EditorOpeningTests.cs +++ b/src/tests/win-app-driver/FancyZonesTests/EditorOpeningTests.cs @@ -59,11 +59,10 @@ namespace PowerToysTests WindowsElement errorMessage = null; try { - errorMessage = session.FindElementByName("FancyZones Editor Exception Handler"); + errorMessage = WaitElementByName("FancyZones Editor Exception Handler"); if (errorMessage != null) { errorMessage.FindElementByName("OK").Click(); - ShortWait(); } } catch (OpenQA.Selenium.WebDriverException) @@ -92,16 +91,12 @@ namespace PowerToysTests Assert.IsNotNull(editorButton); editorButton.Click(); - ShortWait(); - TestEditorOpened(); } void OpenEditorByHotkey() { new Actions(session).KeyDown(OpenQA.Selenium.Keys.Command).SendKeys("`").KeyUp(OpenQA.Selenium.Keys.Command).Perform(); - ShortWait(); - TestEditorOpened(); } diff --git a/src/tests/win-app-driver/FancyZonesTests/EditorSettingsTests.cs b/src/tests/win-app-driver/FancyZonesTests/EditorSettingsTests.cs index bc781ffcfa..009862b297 100644 --- a/src/tests/win-app-driver/FancyZonesTests/EditorSettingsTests.cs +++ b/src/tests/win-app-driver/FancyZonesTests/EditorSettingsTests.cs @@ -37,7 +37,7 @@ namespace PowerToysTests { session.FindElementByAccessibilityId("ApplyTemplateButton").Click(); - ShortWait(); + WaitSeconds(1); Assert.AreEqual(editorZoneCountValue, GetEditZonesSetting(editorZoneCount)); OpenEditor(); @@ -57,7 +57,7 @@ namespace PowerToysTests } session.FindElementByAccessibilityId("ApplyTemplateButton").Click(); - ShortWait(); + WaitSeconds(1); Assert.AreEqual(editorZoneCountValue, GetEditZonesSetting(editorZoneCount)); } @@ -74,7 +74,7 @@ namespace PowerToysTests session.FindElementByAccessibilityId("ApplyTemplateButton").Click(); - ShortWait(); + WaitSeconds(1); Assert.AreNotEqual(spaceAroundSettingValue, GetEditZonesSetting(editorShowSpacing)); } @@ -89,7 +89,7 @@ namespace PowerToysTests bool editorShowSpacingValue = spaceAroundSetting.Selected; session.FindElementByAccessibilityId("ApplyTemplateButton").Click(); - ShortWait(); + WaitSeconds(1); string[] validValues = { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" }; @@ -102,7 +102,7 @@ namespace PowerToysTests paddingValue.SendKeys(editorSpacingValue); session.FindElementByAccessibilityId("ApplyTemplateButton").Click(); - ShortWait(); + WaitSeconds(1); Assert.AreEqual(editorShowSpacingValue, GetEditZonesSetting(editorShowSpacing)); Assert.AreEqual(editorSpacingValue, GetEditZonesSetting(editorSpacing)); @@ -118,7 +118,7 @@ namespace PowerToysTests bool editorShowSpacingValue = spaceAroundSetting.Selected; session.FindElementByAccessibilityId("ApplyTemplateButton").Click(); - ShortWait(); + WaitSeconds(1); string[] invalidValues = { "!", "/", "<", "?", "D", "Z", "]", "m", "}", "1.5", "2,5" }; @@ -133,7 +133,7 @@ namespace PowerToysTests paddingValue.SendKeys(value); session.FindElementByAccessibilityId("ApplyTemplateButton").Click(); - ShortWait(); + WaitSeconds(1); Assert.AreEqual(editorShowSpacingValue, GetEditZonesSetting(editorShowSpacing)); Assert.AreEqual(editorSpacingValue, GetEditZonesSetting(editorSpacing)); diff --git a/src/tests/win-app-driver/FancyZonesTests/EditorTemplatesEditTests.cs b/src/tests/win-app-driver/FancyZonesTests/EditorTemplatesEditTests.cs index b772bd7b8b..a74b1d43bc 100644 --- a/src/tests/win-app-driver/FancyZonesTests/EditorTemplatesEditTests.cs +++ b/src/tests/win-app-driver/FancyZonesTests/EditorTemplatesEditTests.cs @@ -18,7 +18,7 @@ namespace PowerToysTests { WindowsElement cancelButton = session.FindElementByXPath("//Window[@Name=\"FancyZones Editor\"]/Window/Button[@Name=\"Cancel\"]"); new Actions(session).MoveToElement(cancelButton).Click().Perform(); - ShortWait(); + WaitSeconds(1); Assert.AreEqual(_defaultZoneSettings, File.ReadAllText(_zoneSettingsPath), "Settings were changed"); } @@ -26,7 +26,7 @@ namespace PowerToysTests private void SaveTest() { new Actions(session).MoveToElement(session.FindElementByName("Save and apply")).Click().Perform(); - ShortWait(); + WaitSeconds(1); JObject settings = JObject.Parse(File.ReadAllText(_zoneSettingsPath)); Assert.AreEqual("Custom Layout 1", settings["custom-zone-sets"][0]["name"]); @@ -188,7 +188,6 @@ namespace PowerToysTests if (editorWindow != null) { editorWindow.SendKeys(OpenQA.Selenium.Keys.Alt + OpenQA.Selenium.Keys.F4); - ShortWait(); } } catch(OpenQA.Selenium.WebDriverException) diff --git a/src/tests/win-app-driver/FancyZonesTests/FancyZonesEditor.cs b/src/tests/win-app-driver/FancyZonesTests/FancyZonesEditor.cs index 5d0cbbb745..ba98f1a991 100644 --- a/src/tests/win-app-driver/FancyZonesTests/FancyZonesEditor.cs +++ b/src/tests/win-app-driver/FancyZonesTests/FancyZonesEditor.cs @@ -1,4 +1,4 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; +using Microsoft.VisualStudio.TestTools.UnitTesting; using OpenQA.Selenium.Appium.Windows; using OpenQA.Selenium.Interactions; @@ -17,8 +17,10 @@ namespace PowerToysTests protected static void OpenEditor() { new Actions(session).KeyDown(OpenQA.Selenium.Keys.Command).SendKeys("`").KeyUp(OpenQA.Selenium.Keys.Command).Perform(); - ShortWait(); - editorWindow = session.FindElementByXPath("//Window[@Name=\"FancyZones Editor\"]"); + //editorWindow = WaitElementByXPath("//Window[@Name=\"FancyZones Editor\"]"); + //may not find editor by name in 0.16.1 + editorWindow = WaitElementByAccessibilityId("MainWindow1"); + Assert.IsNotNull(editorWindow, "Couldn't find editor window"); } protected static void CloseEditor() @@ -28,7 +30,6 @@ namespace PowerToysTests if (editorWindow != null) { editorWindow.SendKeys(OpenQA.Selenium.Keys.Alt + OpenQA.Selenium.Keys.F4); - ShortWait(); } } catch (OpenQA.Selenium.WebDriverException) diff --git a/src/tests/win-app-driver/FancyZonesTests/FancyZonesSettingsTests.cs b/src/tests/win-app-driver/FancyZonesTests/FancyZonesSettingsTests.cs index 70f7edf67f..d655b7960b 100644 --- a/src/tests/win-app-driver/FancyZonesTests/FancyZonesSettingsTests.cs +++ b/src/tests/win-app-driver/FancyZonesTests/FancyZonesSettingsTests.cs @@ -25,8 +25,6 @@ namespace PowerToysTests private static void Init() { OpenSettings(); - ShortWait(); - OpenFancyZonesSettings(); _saveButton = session.FindElementByName("Save"); @@ -94,7 +92,7 @@ namespace PowerToysTests Assert.AreEqual(expected.ToString() + "\r\n", editor.Text); SaveChanges(); - ShortWait(); + WaitSeconds(1); int value = GetPropertyValue("fancyzones_highlight_opacity"); Assert.AreEqual(expected, value); @@ -215,7 +213,7 @@ namespace PowerToysTests action.Perform(); SaveChanges(); - ShortWait(); + WaitSeconds(1); //Assert.AreEqual(expectedText, input.Text); @@ -235,7 +233,7 @@ namespace PowerToysTests //black on the bottom new Actions(session).MoveToElement(saturationAndBrightness).ClickAndHold().MoveByOffset(0, satRect.Height).Release().Perform(); - ShortWait(); + WaitSeconds(1); Assert.AreEqual("0\r\n", red.Text); Assert.AreEqual("0\r\n", green.Text); @@ -243,7 +241,7 @@ namespace PowerToysTests Assert.AreEqual("000000\r\n", hex.Text); SaveChanges(); - ShortWait(); + WaitSeconds(1); Assert.AreEqual("#000000", GetPropertyValue(propertyName)); //white in left corner @@ -254,7 +252,7 @@ namespace PowerToysTests Assert.AreEqual("ffffff\r\n", hex.Text); SaveChanges(); - ShortWait(); + WaitSeconds(1); Assert.AreEqual("#ffffff", GetPropertyValue(propertyName)); //color in right corner @@ -266,7 +264,7 @@ namespace PowerToysTests Assert.AreEqual("ff0000\r\n", hex.Text); SaveChanges(); - ShortWait(); + WaitSeconds(1); Assert.AreEqual("#ff0000", GetPropertyValue(propertyName)); } @@ -299,9 +297,10 @@ namespace PowerToysTests toggle.Click(); SaveChanges(); - ShortWait(); } - + + WaitSeconds(1); + //check saved settings JObject savedProps = GetProperties(); Assert.AreNotEqual(toggleValues[0], GetPropertyValue(savedProps, "fancyzones_shiftDrag")); @@ -339,7 +338,7 @@ namespace PowerToysTests } SaveChanges(); - ShortWait(); + WaitSeconds(1); JObject savedProps = GetProperties(); Assert.AreEqual(toggleValues[0], GetPropertyValue(savedProps, "fancyzones_shiftDrag")); @@ -396,7 +395,7 @@ namespace PowerToysTests Actions action = new Actions(session); action.MoveToElement(editor).MoveByOffset(editorRect.Width / 2 + 10, -editorRect.Height / 4).Perform(); - ShortWait(); + WaitSeconds(1); action.Click().Perform(); Assert.AreEqual("100\r\n", editor.Text); @@ -421,7 +420,7 @@ namespace PowerToysTests Actions action = new Actions(session); action.MoveToElement(editor).MoveByOffset(editorRect.Width / 2 + 10, editorRect.Height / 4).Perform(); - ShortWait(); + WaitSeconds(1); action.Click().Perform(); Assert.AreEqual("0\r\n", editor.Text); @@ -494,7 +493,7 @@ namespace PowerToysTests Assert.AreEqual("152", hue.Text); SaveChanges(); - ShortWait(); + WaitSeconds(1); Assert.AreEqual("#63c99a", GetPropertyValue("fancyzones_zoneHighlightColor")); } @@ -565,7 +564,7 @@ namespace PowerToysTests input.SendKeys(inputValue); SaveChanges(); ClearInput(input); - ShortWait(); + WaitSeconds(1); Assert.AreEqual(inputValue, GetPropertyValue("fancyzones_excluded_apps")); //invalid @@ -573,28 +572,28 @@ namespace PowerToysTests input.SendKeys(inputValue); SaveChanges(); ClearInput(input); - ShortWait(); + WaitSeconds(1); Assert.AreEqual(inputValue, GetPropertyValue("fancyzones_excluded_apps")); inputValue = "Notepad,Chrome"; input.SendKeys(inputValue); SaveChanges(); ClearInput(input); - ShortWait(); + WaitSeconds(1); Assert.AreEqual(inputValue, GetPropertyValue("fancyzones_excluded_apps")); inputValue = "Note*"; input.SendKeys(inputValue); SaveChanges(); ClearInput(input); - ShortWait(); + WaitSeconds(1); Assert.AreEqual(inputValue, GetPropertyValue("fancyzones_excluded_apps")); inputValue = "Кириллица"; input.SendKeys(inputValue); SaveChanges(); ClearInput(input); - ShortWait(); + WaitSeconds(1); Assert.AreEqual(inputValue, GetPropertyValue("fancyzones_excluded_apps")); } diff --git a/src/tests/win-app-driver/PowerToysSession.cs b/src/tests/win-app-driver/PowerToysSession.cs index 490e2bf39e..150938367f 100644 --- a/src/tests/win-app-driver/PowerToysSession.cs +++ b/src/tests/win-app-driver/PowerToysSession.cs @@ -13,6 +13,8 @@ namespace PowerToysTests public class PowerToysSession { 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; @@ -66,14 +68,27 @@ namespace PowerToysTests { Thread.Sleep(TimeSpan.FromSeconds(seconds)); } - - public static void ShortWait() - { - Thread.Sleep(TimeSpan.FromSeconds(0.5)); + + //Trying to find element by XPath + protected static WindowsElement WaitElementByName(string name, double maxTime = 10) + { + WindowsElement result = null; + Stopwatch timer = new Stopwatch(); + timer.Start(); + while (timer.Elapsed < TimeSpan.FromSeconds(maxTime)) + { + try + { + result = session.FindElementByName(name); + } + catch { } + return result; + } + return null; } //Trying to find element by XPath - protected WindowsElement WaitElementByXPath(string xPath, double maxTime = 10) + protected static WindowsElement WaitElementByXPath(string xPath, double maxTime = 10) { WindowsElement result = null; Stopwatch timer = new Stopwatch(); @@ -85,17 +100,13 @@ namespace PowerToysTests result = session.FindElementByXPath(xPath); } catch { } - if (result != null) - { - return result; - } + return result; } - Assert.IsNotNull(result); return null; } //Trying to find element by AccessibilityId - protected WindowsElement WaitElementByAccessibilityId(string accessibilityId, double maxTime = 10) + protected static WindowsElement WaitElementByAccessibilityId(string accessibilityId, double maxTime = 10) { WindowsElement result = null; Stopwatch timer = new Stopwatch(); @@ -107,12 +118,8 @@ namespace PowerToysTests result = session.FindElementByAccessibilityId(accessibilityId); } catch { } - if (result != null) - { - return result; - } + return result; } - Assert.IsNotNull(result); return null; } @@ -125,13 +132,11 @@ namespace PowerToysTests public static void OpenFancyZonesSettings() { - WindowsElement fzNavigationButton = session.FindElementByXPath("//Button[@Name=\"FancyZones\"]"); + WindowsElement fzNavigationButton = WaitElementByXPath("//Button[@Name=\"FancyZones\"]"); Assert.IsNotNull(fzNavigationButton); fzNavigationButton.Click(); fzNavigationButton.Click(); - - ShortWait(); } public static void CloseSettings() @@ -157,7 +162,7 @@ namespace PowerToysTests try { - WindowsElement pt = session.FindElementByXPath("//Button[@Name=\"PowerToys\"]"); + WindowsElement pt = WaitElementByXPath("//Button[@Name=\"PowerToys\"]"); isLaunched = (pt != null); } catch(OpenQA.Selenium.WebDriverException) @@ -174,11 +179,9 @@ namespace PowerToysTests try { AppiumOptions opts = new AppiumOptions(); - opts.PlatformName = "Windows"; - opts.AddAdditionalCapability("platformVersion", "10"); - opts.AddAdditionalCapability("deviceName", "WindowsPC"); - opts.AddAdditionalCapability("app", "C:/Program Files/PowerToys/PowerToys.exe"); - + opts.PlatformName = "Windows"; + opts.AddAdditionalCapability("app", AppPath); + WindowsDriver driver = new WindowsDriver(new Uri(WindowsApplicationDriverUrl), opts); Assert.IsNotNull(driver); driver.LaunchApp(); @@ -195,13 +198,12 @@ namespace PowerToysTests public static void ExitPowerToys() { trayButton.Click(); - ShortWait(); - WindowsElement pt = session.FindElementByXPath("//Button[@Name=\"PowerToys\"]"); + WindowsElement pt = WaitElementByXPath("//Button[@Name=\"PowerToys\"]"); + Assert.IsNotNull(pt, "Couldn't find \'PowerToys\' button"); new Actions(session).MoveToElement(pt).ContextClick().Perform(); - ShortWait(); - - session.FindElementByXPath("//MenuItem[@Name=\"Exit\"]").Click(); + + WaitElementByXPath("//MenuItem[@Name=\"Exit\"]").Click(); trayButton.Click(); //close tray isPowerToysLaunched = false; } diff --git a/src/tests/win-app-driver/PowerToysTrayTests.cs b/src/tests/win-app-driver/PowerToysTrayTests.cs index 40be624014..304cb8e0bf 100644 --- a/src/tests/win-app-driver/PowerToysTrayTests.cs +++ b/src/tests/win-app-driver/PowerToysTrayTests.cs @@ -15,10 +15,9 @@ namespace PowerToysTests public void SettingsOpen() { OpenSettings(); - ShortWait(); //check settings window opened - WindowsElement settingsWindow = session.FindElementByName("PowerToys Settings"); + WindowsElement settingsWindow = WaitElementByName("PowerToys Settings"); Assert.IsNotNull(settingsWindow); isSettingsOpened = true; @@ -36,14 +35,12 @@ namespace PowerToysTests Assert.IsNotNull(pt); new Actions(session).MoveToElement(pt).ContextClick().Perform(); - ShortWait(); - + //open settings - session.FindElementByXPath("//MenuItem[@Name=\"Settings\"]").Click(); - ShortWait(); - + WaitElementByXPath("//MenuItem[@Name=\"Settings\"]").Click(); + //check settings window opened - WindowsElement settingsWindow = session.FindElementByName("PowerToys Settings"); + WindowsElement settingsWindow = WaitElementByName("PowerToys Settings"); Assert.IsNotNull(settingsWindow); isSettingsOpened = true; @@ -62,12 +59,10 @@ namespace PowerToysTests Assert.IsNotNull(powerToys); new Actions(session).MoveToElement(powerToys).ContextClick().Perform(); - ShortWait(); - + //exit - session.FindElementByXPath("//MenuItem[@Name=\"Exit\"]").Click(); - ShortWait(); - + WaitElementByXPath("//MenuItem[@Name=\"Exit\"]").Click(); + //check PowerToys exited powerToys = null; try @@ -82,8 +77,6 @@ namespace PowerToysTests } LaunchPowerToys(); - ShortWait(); - Assert.IsNull(powerToys); }