diff --git a/src/tests/win-app-driver/FancyZonesTests/EditorSettingsTests.cs b/src/tests/win-app-driver/FancyZonesTests/EditorSettingsTests.cs new file mode 100644 index 0000000000..7fb92abe45 --- /dev/null +++ b/src/tests/win-app-driver/FancyZonesTests/EditorSettingsTests.cs @@ -0,0 +1,97 @@ +using System; +using System.IO; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Newtonsoft.Json.Linq; +using OpenQA.Selenium; +using OpenQA.Selenium.Appium.Windows; + +namespace PowerToysTests +{ + [TestClass] + public class FancyZonesEditorSettingsTests : PowerToysSession + { + [TestMethod] + public void ZoneCount() + { + ShortWait(); + OpenFancyZonesSettings(); + + WindowsElement editorButton = WaitElementByXPath("//Button[@Name=\"Edit zones\"]"); + editorButton.Click(); + + WindowsElement minusButton = WaitElementByAccessibilityId("decrementZones"); + WindowsElement zoneCount = WaitElementByAccessibilityId("zoneCount"); + WindowsElement applyButton; + + int zoneCountQty; + Assert.IsTrue(Int32.TryParse(zoneCount.Text, out zoneCountQty)); + + for (int i = zoneCountQty - 1, j = 0; i > -5; --i, ++j) + { + minusButton.Click(); + + Assert.IsTrue(Int32.TryParse(zoneCount.Text, out zoneCountQty)); + Assert.AreEqual(Math.Max(i, 1), zoneCountQty); + + if (j == 0 || i == -4) + { + applyButton = WaitElementByAccessibilityId("ApplyTemplateButton"); + applyButton.Click(); + ShortWait(); + Assert.AreEqual(zoneCountQty, getSavedZoneCount()); + editorButton.Click(); + minusButton = WaitElementByAccessibilityId("decrementZones"); + zoneCount = WaitElementByAccessibilityId("zoneCount"); + } + } + + WindowsElement plusButton = WaitElementByAccessibilityId("incrementZones"); + + for (int i = 2; i < 45; ++i) + { + plusButton.Click(); + + Assert.IsTrue(Int32.TryParse(zoneCount.Text, out zoneCountQty)); + Assert.AreEqual(Math.Min(i, 40), zoneCountQty); + } + + applyButton = WaitElementByAccessibilityId("ApplyTemplateButton"); + applyButton.Click(); + ShortWait(); + Assert.AreEqual(zoneCountQty, getSavedZoneCount()); + } + + private int getSavedZoneCount() + { + JObject zoneSettings = JObject.Parse(File.ReadAllText(_zoneSettingsPath)); + int editorZoneCount = (int)zoneSettings["devices"][0]["editor-zone-count"]; + return editorZoneCount; + } + + [ClassInitialize] + public static void ClassInitialize(TestContext context) + { + Setup(context); + OpenSettings(); + } + + [ClassCleanup] + public static void ClassCleanup() + { + CloseSettings(); + TearDown(); + } + + [TestInitialize] + public void TestInitialize() + { + + } + + [TestCleanup] + public void TestCleanup() + { + + } + } +} \ No newline at end of file diff --git a/src/tests/win-app-driver/PowerToysSession.cs b/src/tests/win-app-driver/PowerToysSession.cs index a5b1d45b2d..554b279f7f 100644 --- a/src/tests/win-app-driver/PowerToysSession.cs +++ b/src/tests/win-app-driver/PowerToysSession.cs @@ -1,4 +1,5 @@ using System; +using System.Diagnostics; using System.IO; using System.Threading; using Microsoft.VisualStudio.TestTools.UnitTesting; @@ -87,7 +88,7 @@ namespace PowerToysTests } } - public static void WaitSeconds(int seconds) + public static void WaitSeconds(double seconds) { Thread.Sleep(TimeSpan.FromSeconds(seconds)); } @@ -95,6 +96,50 @@ namespace PowerToysTests public static void ShortWait() { Thread.Sleep(TimeSpan.FromSeconds(0.5)); + } + + //Trying to find element by XPath + protected WindowsElement WaitElementByXPath(string xPath, double maxTime = 10) + { + WindowsElement result = null; + Stopwatch timer = new Stopwatch(); + timer.Start(); + while (timer.Elapsed < TimeSpan.FromSeconds(maxTime)) + { + try + { + result = session.FindElementByXPath(xPath); + } + catch { } + if (result != null) + { + return result; + } + } + Assert.IsNotNull(result); + return null; + } + + //Trying to find element by AccessibilityId + protected WindowsElement WaitElementByAccessibilityId(string accessibilityId, double maxTime = 10) + { + WindowsElement result = null; + Stopwatch timer = new Stopwatch(); + timer.Start(); + while (timer.Elapsed < TimeSpan.FromSeconds(maxTime)) + { + try + { + result = session.FindElementByAccessibilityId(accessibilityId); + } + catch { } + if (result != null) + { + return result; + } + } + Assert.IsNotNull(result); + return null; } public static void OpenSettings() diff --git a/src/tests/win-app-driver/win-app-driver.csproj b/src/tests/win-app-driver/win-app-driver.csproj index 9ef9acbdcc..6176e0e471 100644 --- a/src/tests/win-app-driver/win-app-driver.csproj +++ b/src/tests/win-app-driver/win-app-driver.csproj @@ -1,111 +1,112 @@ - - - - - - Debug - AnyCPU - {880ED251-9E16-4713-9A70-D35FE0C01669} - Library - Properties - PowerToysTests - PowerToysTests - v4.6.1 - 512 - {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} - 15.0 - $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) - $(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages - False - UnitTest - - - - - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - - - - ..\..\..\packages\Appium.WebDriver.4.1.1\lib\net45\Appium.Net.dll - - - ..\..\..\packages\Castle.Core.4.3.1\lib\net45\Castle.Core.dll - True - - - ..\..\..\packages\MSTest.TestFramework.2.1.0\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.dll - True - - - ..\..\..\packages\MSTest.TestFramework.2.1.0\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll - True - - - ..\..\..\packages\Newtonsoft.Json.12.0.3\lib\net45\Newtonsoft.Json.dll - True - - - ..\..\..\packages\DotNetSeleniumExtras.PageObjects.3.11.0\lib\net45\SeleniumExtras.PageObjects.dll - True - - - C:\Windows\Microsoft.NET\assembly\GAC_MSIL\System\v4.0_4.0.0.0__b77a5c561934e089\System.dll - - - C:\Windows\Microsoft.NET\assembly\GAC_MSIL\System.Configuration\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Configuration.dll - - - C:\Windows\Microsoft.NET\assembly\GAC_MSIL\System.Core\v4.0_4.0.0.0__b77a5c561934e089\System.Core.dll - - - - - ..\..\..\packages\Selenium.WebDriver.3.141.0\lib\net45\WebDriver.dll - True - - - ..\..\..\packages\Selenium.Support.3.141.0\lib\net45\WebDriver.Support.dll - True - - - + + + + + + Debug + AnyCPU + {880ED251-9E16-4713-9A70-D35FE0C01669} + Library + Properties + PowerToysTests + PowerToysTests + v4.6.1 + 512 + {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + 15.0 + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) + $(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages + False + UnitTest + + + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + ..\..\..\packages\Appium.WebDriver.4.1.1\lib\net45\Appium.Net.dll + + + ..\..\..\packages\Castle.Core.4.3.1\lib\net45\Castle.Core.dll + True + + + ..\..\..\packages\MSTest.TestFramework.2.1.0\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.dll + True + + + ..\..\..\packages\MSTest.TestFramework.2.1.0\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll + True + + + ..\..\..\packages\Newtonsoft.Json.12.0.3\lib\net45\Newtonsoft.Json.dll + True + + + ..\..\..\packages\DotNetSeleniumExtras.PageObjects.3.11.0\lib\net45\SeleniumExtras.PageObjects.dll + True + + + C:\Windows\Microsoft.NET\assembly\GAC_MSIL\System\v4.0_4.0.0.0__b77a5c561934e089\System.dll + + + C:\Windows\Microsoft.NET\assembly\GAC_MSIL\System.Configuration\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Configuration.dll + + + C:\Windows\Microsoft.NET\assembly\GAC_MSIL\System.Core\v4.0_4.0.0.0__b77a5c561934e089\System.Core.dll + + + + + ..\..\..\packages\Selenium.WebDriver.3.141.0\lib\net45\WebDriver.dll + True + + + ..\..\..\packages\Selenium.Support.3.141.0\lib\net45\WebDriver.Support.dll + True + + + - - - - - - - - - - - - - - - - - - This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. - - - - - - + + + + + + + + + + + + + + + + + + + This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. + + + + + + \ No newline at end of file