From d0ebc2d09fea28a6ee91cd2e6628e5a7cf766987 Mon Sep 17 00:00:00 2001 From: seraphima Date: Thu, 26 Oct 2023 14:36:10 +0200 Subject: [PATCH] editor test project --- PowerToys.sln | 15 ++++ .../RunFancyZonesEditorTest.cs | 35 +++++++++ .../UITests-FancyZonesEditor.csproj | 30 ++++++++ .../Utils/FancyZonesEditorSession.cs | 71 +++++++++++++++++++ 4 files changed, 151 insertions(+) create mode 100644 src/modules/fancyzones/UITests-FancyZonesEditor/RunFancyZonesEditorTest.cs create mode 100644 src/modules/fancyzones/UITests-FancyZonesEditor/UITests-FancyZonesEditor.csproj create mode 100644 src/modules/fancyzones/UITests-FancyZonesEditor/Utils/FancyZonesEditorSession.cs diff --git a/PowerToys.sln b/PowerToys.sln index f0b5ac9825..6918ee68a4 100644 --- a/PowerToys.sln +++ b/PowerToys.sln @@ -547,6 +547,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "EnvironmentVariablesModuleI EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "UITests-FancyZones", "src\modules\fancyzones\UITests-FancyZones\UITests-FancyZones.csproj", "{FE38FC07-1C05-4B57-ADA3-2FE2F53C6A52}" EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "UITests-FancyZonesEditor", "src\modules\fancyzones\UITests-FancyZonesEditor\UITests-FancyZonesEditor.csproj", "{3A9A791E-94A9-49F8-8401-C11CE288D5FB}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|ARM64 = Debug|ARM64 @@ -2365,6 +2367,18 @@ Global {FE38FC07-1C05-4B57-ADA3-2FE2F53C6A52}.Release|x64.Build.0 = Release|x64 {FE38FC07-1C05-4B57-ADA3-2FE2F53C6A52}.Release|x86.ActiveCfg = Release|x64 {FE38FC07-1C05-4B57-ADA3-2FE2F53C6A52}.Release|x86.Build.0 = Release|x64 + {3A9A791E-94A9-49F8-8401-C11CE288D5FB}.Debug|ARM64.ActiveCfg = Debug|ARM64 + {3A9A791E-94A9-49F8-8401-C11CE288D5FB}.Debug|ARM64.Build.0 = Debug|ARM64 + {3A9A791E-94A9-49F8-8401-C11CE288D5FB}.Debug|x64.ActiveCfg = Debug|x64 + {3A9A791E-94A9-49F8-8401-C11CE288D5FB}.Debug|x64.Build.0 = Debug|x64 + {3A9A791E-94A9-49F8-8401-C11CE288D5FB}.Debug|x86.ActiveCfg = Debug|x64 + {3A9A791E-94A9-49F8-8401-C11CE288D5FB}.Debug|x86.Build.0 = Debug|x64 + {3A9A791E-94A9-49F8-8401-C11CE288D5FB}.Release|ARM64.ActiveCfg = Release|ARM64 + {3A9A791E-94A9-49F8-8401-C11CE288D5FB}.Release|ARM64.Build.0 = Release|ARM64 + {3A9A791E-94A9-49F8-8401-C11CE288D5FB}.Release|x64.ActiveCfg = Release|x64 + {3A9A791E-94A9-49F8-8401-C11CE288D5FB}.Release|x64.Build.0 = Release|x64 + {3A9A791E-94A9-49F8-8401-C11CE288D5FB}.Release|x86.ActiveCfg = Release|x64 + {3A9A791E-94A9-49F8-8401-C11CE288D5FB}.Release|x86.Build.0 = Release|x64 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -2564,6 +2578,7 @@ Global {51465DA1-C18B-4B99-93E1-ECF8E0FA0CBA} = {538ED0BB-B863-4B20-98CC-BCDF7FA0B68A} {B9420661-B0E4-4241-ABD4-4A27A1F64250} = {538ED0BB-B863-4B20-98CC-BCDF7FA0B68A} {FE38FC07-1C05-4B57-ADA3-2FE2F53C6A52} = {D1D6BC88-09AE-4FB4-AD24-5DED46A791DD} + {3A9A791E-94A9-49F8-8401-C11CE288D5FB} = {D1D6BC88-09AE-4FB4-AD24-5DED46A791DD} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {C3A2F9D1-7930-4EF4-A6FC-7EE0A99821D0} diff --git a/src/modules/fancyzones/UITests-FancyZonesEditor/RunFancyZonesEditorTest.cs b/src/modules/fancyzones/UITests-FancyZonesEditor/RunFancyZonesEditorTest.cs new file mode 100644 index 0000000000..c9b0ce97b3 --- /dev/null +++ b/src/modules/fancyzones/UITests-FancyZonesEditor/RunFancyZonesEditorTest.cs @@ -0,0 +1,35 @@ +// Copyright (c) Microsoft Corporation +// The Microsoft Corporation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using Microsoft.FancyZonesEditor.UnitTests.Utils; +using Microsoft.VisualStudio.TestTools.UnitTesting; + +namespace UITests_FancyZonesEditor +{ + [TestClass] + public class RunFancyZonesEditorTest + { + private static FancyZonesEditorSession? _session; + private static TestContext? _context; + + [ClassInitialize] + public static void ClassInitialize(TestContext testContext) + { + _context = testContext; + _session = new FancyZonesEditorSession(testContext); + } + + [ClassCleanup] + public static void ClassCleanup() + { + _session?.Close(_context!); + } + + [TestMethod] + public void RunFancyZonesEditor() + { + Assert.IsNotNull(_session?.Session); + } + } +} diff --git a/src/modules/fancyzones/UITests-FancyZonesEditor/UITests-FancyZonesEditor.csproj b/src/modules/fancyzones/UITests-FancyZonesEditor/UITests-FancyZonesEditor.csproj new file mode 100644 index 0000000000..2076740143 --- /dev/null +++ b/src/modules/fancyzones/UITests-FancyZonesEditor/UITests-FancyZonesEditor.csproj @@ -0,0 +1,30 @@ + + + + + net7.0-windows10.0.20348.0 + 10.0.19041.0 + 10.0.19041.0 + {3A9A791E-94A9-49F8-8401-C11CE288D5FB} + Microsoft.FancyZonesEditor.UITests + false + enable + Library + $(Version).0 + + + + ..\..\..\..\$(Platform)\$(Configuration)\tests\UITests-FancyZonesEditor\ + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/modules/fancyzones/UITests-FancyZonesEditor/Utils/FancyZonesEditorSession.cs b/src/modules/fancyzones/UITests-FancyZonesEditor/Utils/FancyZonesEditorSession.cs new file mode 100644 index 0000000000..a3ab427036 --- /dev/null +++ b/src/modules/fancyzones/UITests-FancyZonesEditor/Utils/FancyZonesEditorSession.cs @@ -0,0 +1,71 @@ +// Copyright (c) Microsoft Corporation +// The Microsoft Corporation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.IO; +using System.Reflection; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using OpenQA.Selenium; +using OpenQA.Selenium.Appium; +using OpenQA.Selenium.Appium.Windows; + +namespace Microsoft.FancyZonesEditor.UnitTests.Utils +{ + public class FancyZonesEditorSession + { + protected const string WindowsApplicationDriverUrl = "http://127.0.0.1:4723"; + private const string FancyZonesEditorPath = @"\..\..\..\PowerToys.FancyZonesEditor.exe"; + + public WindowsDriver? Session { get; } + + public WindowsElement? MainEditorWindow { get; } + + public FancyZonesEditorSession(TestContext testContext) + { + try + { + // Launch FancyZonesEditor + string? path = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); + path += FancyZonesEditorPath; + + AppiumOptions opts = new AppiumOptions(); + opts.AddAdditionalCapability("app", path); + Session = new WindowsDriver(new Uri(WindowsApplicationDriverUrl), opts); + } + catch (Exception ex) + { + testContext.WriteLine(ex.Message); + } + + Assert.IsNotNull(Session); + + // Set implicit timeout to 1.5 seconds to make element search to retry every 500 ms for at most three times + Session.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(1.5); + + // Find main editor window + MainEditorWindow = Session.FindElementByAccessibilityId("MainWindow1"); + Assert.IsNotNull(MainEditorWindow); + } + + public void Close(TestContext testContext) + { + // Close the session + if (Session != null) + { + try + { + // FZEditor applciation can be closed by explicitly closing main editor window + MainEditorWindow?.SendKeys(Keys.Alt + Keys.F4); + } + catch (Exception ex) + { + testContext.WriteLine(ex.Message); + } + + Session.Quit(); + Session.Dispose(); + } + } + } +}