From 05e1854c4a2f71791dbb5e7f1f628f62250c76da Mon Sep 17 00:00:00 2001 From: Serafima Zykova Date: Wed, 26 Feb 2020 21:05:46 +0300 Subject: [PATCH 01/33] added test project --- PowerToys.sln | 61 ++++++++ src/tests/win-app-driver/PowerToysSession.cs | 40 +++++ .../win-app-driver/Properties/AssemblyInfo.cs | 20 +++ src/tests/win-app-driver/README.md | 53 +++++++ .../win-app-driver/TestShortcutHelper.cs | 148 ++++++++++++++++++ src/tests/win-app-driver/packages.config | 11 ++ .../win-app-driver/win-app-driver.csproj | 106 +++++++++++++ 7 files changed, 439 insertions(+) create mode 100644 src/tests/win-app-driver/PowerToysSession.cs create mode 100644 src/tests/win-app-driver/Properties/AssemblyInfo.cs create mode 100644 src/tests/win-app-driver/README.md create mode 100644 src/tests/win-app-driver/TestShortcutHelper.cs create mode 100644 src/tests/win-app-driver/packages.config create mode 100644 src/tests/win-app-driver/win-app-driver.csproj diff --git a/PowerToys.sln b/PowerToys.sln index 34d6e639651b..a101942620e1 100644 --- a/PowerToys.sln +++ b/PowerToys.sln @@ -138,6 +138,10 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "action_runner", "src\action EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "msi_to_msix_upgrade_lib", "src\common\msi_to_msix_upgrade_lib\msi_to_msix_upgrade_lib.vcxproj", "{17DA04DF-E393-4397-9CF0-84DABE11032E}" EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{E775CC2C-24CB-48D6-9C3A-BE4CCE0DB17A}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "win-app-driver", "src\tests\win-app-driver\win-app-driver.csproj", "{880ED251-9E16-4713-9A70-D35FE0C01669}" +EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "previewpane", "previewpane", "{2F305555-C296-497E-AC20-5FA1B237996A}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PreviewHandlerCommon", "src\modules\previewpane\Common\PreviewHandlerCommon.csproj", "{AF2349B8-E5B6-4004-9502-687C1C7730B1}" @@ -158,78 +162,115 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "powerpreviewTest", "src\mod EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU Debug|x64 = Debug|x64 + Release|Any CPU = Release|Any CPU Release|x64 = Release|x64 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution + {9412D5C6-2CF2-4FC2-A601-B55508EA9B27}.Debug|Any CPU.ActiveCfg = Debug|x64 {9412D5C6-2CF2-4FC2-A601-B55508EA9B27}.Debug|x64.ActiveCfg = Debug|x64 {9412D5C6-2CF2-4FC2-A601-B55508EA9B27}.Debug|x64.Build.0 = Debug|x64 + {9412D5C6-2CF2-4FC2-A601-B55508EA9B27}.Release|Any CPU.ActiveCfg = Release|x64 {9412D5C6-2CF2-4FC2-A601-B55508EA9B27}.Release|x64.ActiveCfg = Release|x64 {9412D5C6-2CF2-4FC2-A601-B55508EA9B27}.Release|x64.Build.0 = Release|x64 + {74485049-C722-400F-ABE5-86AC52D929B3}.Debug|Any CPU.ActiveCfg = Debug|x64 {74485049-C722-400F-ABE5-86AC52D929B3}.Debug|x64.ActiveCfg = Debug|x64 {74485049-C722-400F-ABE5-86AC52D929B3}.Debug|x64.Build.0 = Debug|x64 + {74485049-C722-400F-ABE5-86AC52D929B3}.Release|Any CPU.ActiveCfg = Release|x64 {74485049-C722-400F-ABE5-86AC52D929B3}.Release|x64.ActiveCfg = Release|x64 {74485049-C722-400F-ABE5-86AC52D929B3}.Release|x64.Build.0 = Release|x64 + {A46629C4-1A6C-40FA-A8B6-10E5102BB0BA}.Debug|Any CPU.ActiveCfg = Debug|x64 {A46629C4-1A6C-40FA-A8B6-10E5102BB0BA}.Debug|x64.ActiveCfg = Debug|x64 {A46629C4-1A6C-40FA-A8B6-10E5102BB0BA}.Debug|x64.Build.0 = Debug|x64 + {A46629C4-1A6C-40FA-A8B6-10E5102BB0BA}.Release|Any CPU.ActiveCfg = Release|x64 {A46629C4-1A6C-40FA-A8B6-10E5102BB0BA}.Release|x64.ActiveCfg = Release|x64 {A46629C4-1A6C-40FA-A8B6-10E5102BB0BA}.Release|x64.Build.0 = Release|x64 + {44CC9375-3E6E-4D99-8913-7FB748807EBD}.Debug|Any CPU.ActiveCfg = Debug|x64 {44CC9375-3E6E-4D99-8913-7FB748807EBD}.Debug|x64.ActiveCfg = Debug|x64 {44CC9375-3E6E-4D99-8913-7FB748807EBD}.Debug|x64.Build.0 = Debug|x64 + {44CC9375-3E6E-4D99-8913-7FB748807EBD}.Release|Any CPU.ActiveCfg = Release|x64 {44CC9375-3E6E-4D99-8913-7FB748807EBD}.Release|x64.ActiveCfg = Release|x64 {44CC9375-3E6E-4D99-8913-7FB748807EBD}.Release|x64.Build.0 = Release|x64 + {07C389E3-6BC8-41CF-923E-307B1265FA2D}.Debug|Any CPU.ActiveCfg = Debug|x64 {07C389E3-6BC8-41CF-923E-307B1265FA2D}.Debug|x64.ActiveCfg = Debug|x64 {07C389E3-6BC8-41CF-923E-307B1265FA2D}.Debug|x64.Build.0 = Debug|x64 + {07C389E3-6BC8-41CF-923E-307B1265FA2D}.Release|Any CPU.ActiveCfg = Release|x64 {07C389E3-6BC8-41CF-923E-307B1265FA2D}.Release|x64.ActiveCfg = Release|x64 {07C389E3-6BC8-41CF-923E-307B1265FA2D}.Release|x64.Build.0 = Release|x64 + {F9C68EDF-AC74-4B77-9AF1-005D9C9F6A99}.Debug|Any CPU.ActiveCfg = Debug|x64 {F9C68EDF-AC74-4B77-9AF1-005D9C9F6A99}.Debug|x64.ActiveCfg = Debug|x64 {F9C68EDF-AC74-4B77-9AF1-005D9C9F6A99}.Debug|x64.Build.0 = Debug|x64 + {F9C68EDF-AC74-4B77-9AF1-005D9C9F6A99}.Release|Any CPU.ActiveCfg = Release|x64 {F9C68EDF-AC74-4B77-9AF1-005D9C9F6A99}.Release|x64.ActiveCfg = Release|x64 {F9C68EDF-AC74-4B77-9AF1-005D9C9F6A99}.Release|x64.Build.0 = Release|x64 + {48804216-2A0E-4168-A6D8-9CD068D14227}.Debug|Any CPU.ActiveCfg = Debug|x64 {48804216-2A0E-4168-A6D8-9CD068D14227}.Debug|x64.ActiveCfg = Debug|x64 {48804216-2A0E-4168-A6D8-9CD068D14227}.Debug|x64.Build.0 = Debug|x64 + {48804216-2A0E-4168-A6D8-9CD068D14227}.Release|Any CPU.ActiveCfg = Release|x64 {48804216-2A0E-4168-A6D8-9CD068D14227}.Release|x64.ActiveCfg = Release|x64 {48804216-2A0E-4168-A6D8-9CD068D14227}.Release|x64.Build.0 = Release|x64 + {9C6A7905-72D4-4BF5-B256-ABFDAEF68AE9}.Debug|Any CPU.ActiveCfg = Debug|x64 {9C6A7905-72D4-4BF5-B256-ABFDAEF68AE9}.Debug|x64.ActiveCfg = Debug|x64 {9C6A7905-72D4-4BF5-B256-ABFDAEF68AE9}.Debug|x64.Build.0 = Debug|x64 + {9C6A7905-72D4-4BF5-B256-ABFDAEF68AE9}.Release|Any CPU.ActiveCfg = Release|x64 {9C6A7905-72D4-4BF5-B256-ABFDAEF68AE9}.Release|x64.ActiveCfg = Release|x64 {9C6A7905-72D4-4BF5-B256-ABFDAEF68AE9}.Release|x64.Build.0 = Release|x64 + {1A066C63-64B3-45F8-92FE-664E1CCE8077}.Debug|Any CPU.ActiveCfg = Debug|x64 {1A066C63-64B3-45F8-92FE-664E1CCE8077}.Debug|x64.ActiveCfg = Debug|x64 {1A066C63-64B3-45F8-92FE-664E1CCE8077}.Debug|x64.Build.0 = Debug|x64 + {1A066C63-64B3-45F8-92FE-664E1CCE8077}.Release|Any CPU.ActiveCfg = Release|x64 {1A066C63-64B3-45F8-92FE-664E1CCE8077}.Release|x64.ActiveCfg = Release|x64 {1A066C63-64B3-45F8-92FE-664E1CCE8077}.Release|x64.Build.0 = Release|x64 + {5CCC8468-DEC8-4D36-99D4-5C891BEBD481}.Debug|Any CPU.ActiveCfg = Debug|x64 {5CCC8468-DEC8-4D36-99D4-5C891BEBD481}.Debug|x64.ActiveCfg = Debug|x64 {5CCC8468-DEC8-4D36-99D4-5C891BEBD481}.Debug|x64.Build.0 = Debug|x64 + {5CCC8468-DEC8-4D36-99D4-5C891BEBD481}.Release|Any CPU.ActiveCfg = Release|x64 {5CCC8468-DEC8-4D36-99D4-5C891BEBD481}.Release|x64.ActiveCfg = Release|x64 {5CCC8468-DEC8-4D36-99D4-5C891BEBD481}.Release|x64.Build.0 = Release|x64 + {B25AC7A5-FB9F-4789-B392-D5C85E948670}.Debug|Any CPU.ActiveCfg = Debug|Win32 {B25AC7A5-FB9F-4789-B392-D5C85E948670}.Debug|x64.ActiveCfg = Debug|x64 {B25AC7A5-FB9F-4789-B392-D5C85E948670}.Debug|x64.Build.0 = Debug|x64 + {B25AC7A5-FB9F-4789-B392-D5C85E948670}.Release|Any CPU.ActiveCfg = Release|Win32 {B25AC7A5-FB9F-4789-B392-D5C85E948670}.Release|x64.ActiveCfg = Release|x64 {B25AC7A5-FB9F-4789-B392-D5C85E948670}.Release|x64.Build.0 = Release|x64 + {51920F1F-C28C-4ADF-8660-4238766796C2}.Debug|Any CPU.ActiveCfg = Debug|Win32 {51920F1F-C28C-4ADF-8660-4238766796C2}.Debug|x64.ActiveCfg = Debug|x64 {51920F1F-C28C-4ADF-8660-4238766796C2}.Debug|x64.Build.0 = Debug|x64 + {51920F1F-C28C-4ADF-8660-4238766796C2}.Release|Any CPU.ActiveCfg = Release|Win32 {51920F1F-C28C-4ADF-8660-4238766796C2}.Release|x64.ActiveCfg = Release|x64 {51920F1F-C28C-4ADF-8660-4238766796C2}.Release|x64.Build.0 = Release|x64 + {0E072714-D127-460B-AFAD-B4C40B412798}.Debug|Any CPU.ActiveCfg = Debug|x64 {0E072714-D127-460B-AFAD-B4C40B412798}.Debug|x64.ActiveCfg = Debug|x64 {0E072714-D127-460B-AFAD-B4C40B412798}.Debug|x64.Build.0 = Debug|x64 + {0E072714-D127-460B-AFAD-B4C40B412798}.Release|Any CPU.ActiveCfg = Release|x64 {0E072714-D127-460B-AFAD-B4C40B412798}.Release|x64.ActiveCfg = Release|x64 {0E072714-D127-460B-AFAD-B4C40B412798}.Release|x64.Build.0 = Release|x64 + {A3935CF4-46C5-4A88-84D3-6B12E16E6BA2}.Debug|Any CPU.ActiveCfg = Debug|Win32 {A3935CF4-46C5-4A88-84D3-6B12E16E6BA2}.Debug|x64.ActiveCfg = Debug|x64 {A3935CF4-46C5-4A88-84D3-6B12E16E6BA2}.Debug|x64.Build.0 = Debug|x64 + {A3935CF4-46C5-4A88-84D3-6B12E16E6BA2}.Release|Any CPU.ActiveCfg = Release|Win32 {A3935CF4-46C5-4A88-84D3-6B12E16E6BA2}.Release|x64.ActiveCfg = Release|x64 {A3935CF4-46C5-4A88-84D3-6B12E16E6BA2}.Release|x64.Build.0 = Release|x64 + {2151F984-E006-4A9F-92EF-C6DDE3DC8413}.Debug|Any CPU.ActiveCfg = Debug|Win32 {2151F984-E006-4A9F-92EF-C6DDE3DC8413}.Debug|x64.ActiveCfg = Debug|x64 {2151F984-E006-4A9F-92EF-C6DDE3DC8413}.Debug|x64.Build.0 = Debug|x64 + {2151F984-E006-4A9F-92EF-C6DDE3DC8413}.Release|Any CPU.ActiveCfg = Release|Win32 {2151F984-E006-4A9F-92EF-C6DDE3DC8413}.Release|x64.ActiveCfg = Release|x64 {2151F984-E006-4A9F-92EF-C6DDE3DC8413}.Release|x64.Build.0 = Release|x64 + {64A80062-4D8B-4229-8A38-DFA1D7497749}.Debug|Any CPU.ActiveCfg = Debug|x64 {64A80062-4D8B-4229-8A38-DFA1D7497749}.Debug|x64.ActiveCfg = Debug|x64 {64A80062-4D8B-4229-8A38-DFA1D7497749}.Debug|x64.Build.0 = Debug|x64 + {64A80062-4D8B-4229-8A38-DFA1D7497749}.Release|Any CPU.ActiveCfg = Release|x64 {64A80062-4D8B-4229-8A38-DFA1D7497749}.Release|x64.ActiveCfg = Release|x64 {64A80062-4D8B-4229-8A38-DFA1D7497749}.Release|x64.Build.0 = Release|x64 + {0485F45C-EA7A-4BB5-804B-3E8D14699387}.Debug|Any CPU.ActiveCfg = Debug|x64 {0485F45C-EA7A-4BB5-804B-3E8D14699387}.Debug|x64.ActiveCfg = Debug|x64 {0485F45C-EA7A-4BB5-804B-3E8D14699387}.Debug|x64.Build.0 = Debug|x64 + {0485F45C-EA7A-4BB5-804B-3E8D14699387}.Release|Any CPU.ActiveCfg = Release|x64 {0485F45C-EA7A-4BB5-804B-3E8D14699387}.Release|x64.ActiveCfg = Release|x64 {0485F45C-EA7A-4BB5-804B-3E8D14699387}.Release|x64.Build.0 = Release|x64 + {0B593A6C-4143-4337-860E-DB5710FB87DB}.Debug|Any CPU.ActiveCfg = Debug|Win32 {2BE46397-4DFA-414C-9BD4-41E4BBF8CB34}.Debug|x64.ActiveCfg = Debug|x64 {2BE46397-4DFA-414C-9BD4-41E4BBF8CB34}.Debug|x64.Build.0 = Debug|x64 {2BE46397-4DFA-414C-9BD4-41E4BBF8CB34}.Release|x64.ActiveCfg = Release|x64 @@ -244,28 +285,47 @@ Global {E0CC7526-D85E-43AC-844F-D5DF0D2F5AB8}.Release|x64.Build.0 = Release|x64 {0B593A6C-4143-4337-860E-DB5710FB87DB}.Debug|x64.ActiveCfg = Debug|x64 {0B593A6C-4143-4337-860E-DB5710FB87DB}.Debug|x64.Build.0 = Debug|x64 + {0B593A6C-4143-4337-860E-DB5710FB87DB}.Release|Any CPU.ActiveCfg = Release|Win32 {0B593A6C-4143-4337-860E-DB5710FB87DB}.Release|x64.ActiveCfg = Release|x64 {0B593A6C-4143-4337-860E-DB5710FB87DB}.Release|x64.Build.0 = Release|x64 + {031AC72E-FA28-4AB7-B690-6F7B9C28AA73}.Debug|Any CPU.ActiveCfg = Debug|Win32 {031AC72E-FA28-4AB7-B690-6F7B9C28AA73}.Debug|x64.ActiveCfg = Debug|x64 {031AC72E-FA28-4AB7-B690-6F7B9C28AA73}.Debug|x64.Build.0 = Debug|x64 + {031AC72E-FA28-4AB7-B690-6F7B9C28AA73}.Release|Any CPU.ActiveCfg = Release|Win32 {031AC72E-FA28-4AB7-B690-6F7B9C28AA73}.Release|x64.ActiveCfg = Release|x64 {031AC72E-FA28-4AB7-B690-6F7B9C28AA73}.Release|x64.Build.0 = Release|x64 + {B9BDF8BE-FED7-49B5-A7AE-DD4D1CA2D9EB}.Debug|Any CPU.ActiveCfg = Debug|x64 {B9BDF8BE-FED7-49B5-A7AE-DD4D1CA2D9EB}.Debug|x64.ActiveCfg = Debug|x64 {B9BDF8BE-FED7-49B5-A7AE-DD4D1CA2D9EB}.Debug|x64.Build.0 = Debug|x64 + {B9BDF8BE-FED7-49B5-A7AE-DD4D1CA2D9EB}.Release|Any CPU.ActiveCfg = Release|x64 {B9BDF8BE-FED7-49B5-A7AE-DD4D1CA2D9EB}.Release|x64.ActiveCfg = Release|x64 {B9BDF8BE-FED7-49B5-A7AE-DD4D1CA2D9EB}.Release|x64.Build.0 = Release|x64 + {51D3BD1F-07A8-48EB-B2A0-0A249CD4E1A6}.Debug|Any CPU.ActiveCfg = Debug|x64 {51D3BD1F-07A8-48EB-B2A0-0A249CD4E1A6}.Debug|x64.ActiveCfg = Debug|x64 {51D3BD1F-07A8-48EB-B2A0-0A249CD4E1A6}.Debug|x64.Build.0 = Debug|x64 + {51D3BD1F-07A8-48EB-B2A0-0A249CD4E1A6}.Release|Any CPU.ActiveCfg = Release|x64 {51D3BD1F-07A8-48EB-B2A0-0A249CD4E1A6}.Release|x64.ActiveCfg = Release|x64 {51D3BD1F-07A8-48EB-B2A0-0A249CD4E1A6}.Release|x64.Build.0 = Release|x64 + {D29DDD63-E2CF-4657-9FD5-2AEDE4257E5D}.Debug|Any CPU.ActiveCfg = Debug|Win32 {D29DDD63-E2CF-4657-9FD5-2AEDE4257E5D}.Debug|x64.ActiveCfg = Debug|x64 {D29DDD63-E2CF-4657-9FD5-2AEDE4257E5D}.Debug|x64.Build.0 = Debug|x64 + {D29DDD63-E2CF-4657-9FD5-2AEDE4257E5D}.Release|Any CPU.ActiveCfg = Release|Win32 {D29DDD63-E2CF-4657-9FD5-2AEDE4257E5D}.Release|x64.ActiveCfg = Release|x64 {D29DDD63-E2CF-4657-9FD5-2AEDE4257E5D}.Release|x64.Build.0 = Release|x64 + {17DA04DF-E393-4397-9CF0-84DABE11032E}.Debug|Any CPU.ActiveCfg = Debug|Win32 {17DA04DF-E393-4397-9CF0-84DABE11032E}.Debug|x64.ActiveCfg = Debug|x64 {17DA04DF-E393-4397-9CF0-84DABE11032E}.Debug|x64.Build.0 = Debug|x64 + {17DA04DF-E393-4397-9CF0-84DABE11032E}.Release|Any CPU.ActiveCfg = Release|Win32 {17DA04DF-E393-4397-9CF0-84DABE11032E}.Release|x64.ActiveCfg = Release|x64 {17DA04DF-E393-4397-9CF0-84DABE11032E}.Release|x64.Build.0 = Release|x64 + {880ED251-9E16-4713-9A70-D35FE0C01669}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {880ED251-9E16-4713-9A70-D35FE0C01669}.Debug|Any CPU.Build.0 = Debug|Any CPU + {880ED251-9E16-4713-9A70-D35FE0C01669}.Debug|x64.ActiveCfg = Debug|Any CPU + {880ED251-9E16-4713-9A70-D35FE0C01669}.Debug|x64.Build.0 = Debug|Any CPU + {880ED251-9E16-4713-9A70-D35FE0C01669}.Release|Any CPU.ActiveCfg = Release|Any CPU + {880ED251-9E16-4713-9A70-D35FE0C01669}.Release|Any CPU.Build.0 = Release|Any CPU + {880ED251-9E16-4713-9A70-D35FE0C01669}.Release|x64.ActiveCfg = Release|Any CPU + {880ED251-9E16-4713-9A70-D35FE0C01669}.Release|x64.Build.0 = Release|Any CPU {AF2349B8-E5B6-4004-9502-687C1C7730B1}.Debug|x64.ActiveCfg = Debug|x64 {AF2349B8-E5B6-4004-9502-687C1C7730B1}.Debug|x64.Build.0 = Debug|x64 {AF2349B8-E5B6-4004-9502-687C1C7730B1}.Release|x64.ActiveCfg = Release|x64 @@ -331,6 +391,7 @@ Global {B9BDF8BE-FED7-49B5-A7AE-DD4D1CA2D9EB} = {8DC78AF7-DC3E-4C57-A8FB-7E347DE74A03} {51D3BD1F-07A8-48EB-B2A0-0A249CD4E1A6} = {8DC78AF7-DC3E-4C57-A8FB-7E347DE74A03} {17DA04DF-E393-4397-9CF0-84DABE11032E} = {1AFB6476-670D-4E80-A464-657E01DFF482} + {880ED251-9E16-4713-9A70-D35FE0C01669} = {E775CC2C-24CB-48D6-9C3A-BE4CCE0DB17A} {2F305555-C296-497E-AC20-5FA1B237996A} = {4574FDD0-F61D-4376-98BF-E5A1262C11EC} {AF2349B8-E5B6-4004-9502-687C1C7730B1} = {2F305555-C296-497E-AC20-5FA1B237996A} {6A71162E-FC4C-4A2C-B90F-3CF94F59A9BB} = {2F305555-C296-497E-AC20-5FA1B237996A} diff --git a/src/tests/win-app-driver/PowerToysSession.cs b/src/tests/win-app-driver/PowerToysSession.cs new file mode 100644 index 000000000000..7d7a3d1b0c89 --- /dev/null +++ b/src/tests/win-app-driver/PowerToysSession.cs @@ -0,0 +1,40 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using OpenQA.Selenium.Appium; +using OpenQA.Selenium.Appium.Windows; +using OpenQA.Selenium.Remote; +using OpenQA.Selenium; + +namespace PowerToysTests +{ + public class PowerToysSession + { + protected const string WindowsApplicationDriverUrl = "http://127.0.0.1:4723"; + protected static WindowsDriver session; + + public static void Setup(TestContext context) + { + // TODO: Launch PowerToys application if it is not yet launched + if (session == null) + { + // Create a new Desktop session to use PowerToys. + AppiumOptions appiumOptions = new AppiumOptions(); + appiumOptions.PlatformName = "Windows"; + appiumOptions.AddAdditionalCapability("app", "Root"); + session = new WindowsDriver(new Uri(WindowsApplicationDriverUrl), appiumOptions); + Assert.IsNotNull(session); + } + + } + + public static void TearDown() + { + if (session!=null) + { + session.Quit(); + session = null; + } + } + + } +} diff --git a/src/tests/win-app-driver/Properties/AssemblyInfo.cs b/src/tests/win-app-driver/Properties/AssemblyInfo.cs new file mode 100644 index 000000000000..890399d5f937 --- /dev/null +++ b/src/tests/win-app-driver/Properties/AssemblyInfo.cs @@ -0,0 +1,20 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +[assembly: AssemblyTitle("PowerToysTests")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("PowerToysTests")] +[assembly: AssemblyCopyright("Copyright © 2019")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +[assembly: ComVisible(false)] + +[assembly: Guid("880ed251-9e16-4713-9a70-d35fe0c01669")] + +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/src/tests/win-app-driver/README.md b/src/tests/win-app-driver/README.md new file mode 100644 index 000000000000..c0425a15c6f9 --- /dev/null +++ b/src/tests/win-app-driver/README.md @@ -0,0 +1,53 @@ +# 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 Windows Application Driver in the test machine: https://github.com/Microsoft/WinAppDriver/releases + - Install the ".Net desktop development" components in Visual Studio 2017. It should have support for "C#" and ".Net Framework 4.6.1". + +## Running the tests + +### Preparing the test machine + - Start `powertoys.exe`. + - Set Windows to "Developer Mode", by selecting `Developer mode` in `Settings > For developers > Use developer features` in Windows 10. + - Run the "Windows Application Driver" in Administrator mode in the test machine. + +When testing on a remote machine, 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 in the Development Machine + - Open `powertoys.sln` in Visual Studio 2017. + - 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). diff --git a/src/tests/win-app-driver/TestShortcutHelper.cs b/src/tests/win-app-driver/TestShortcutHelper.cs new file mode 100644 index 000000000000..5a198f361c8b --- /dev/null +++ b/src/tests/win-app-driver/TestShortcutHelper.cs @@ -0,0 +1,148 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using OpenQA.Selenium.Appium; +using OpenQA.Selenium.Appium.Windows; +using OpenQA.Selenium.Remote; +using OpenQA.Selenium; +using System.Threading; + +namespace PowerToysTests +{ + [TestClass] + public class TestShortcutHelper : 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) + { + session.Keyboard.PressKey(Keys.Command); + isWinKeyPressed = true; + } + } + + private void ReleaseWinKey() + { + if(isWinKeyPressed) + { + session.Keyboard.ReleaseKey(Keys.Command); + isWinKeyPressed = false; + } + } + + [TestMethod] + public void AppearsOnWinKeyPress() + { + PressWinKey(); + Thread.Sleep(TimeSpan.FromSeconds(2)); + WindowsElement shortcutHelperWindow = session.FindElementByXPath("/Pane[@ClassName=\"#32769\"]/Pane[@ClassName=\"PToyD2DPopup\"]"); + Assert.IsNotNull(shortcutHelperWindow); + ReleaseWinKey(); + Thread.Sleep(TimeSpan.FromSeconds(2)); + } + [TestMethod] + [ExpectedException(typeof(InvalidOperationException), + "The Shortcut Guide UI was still found after releasing the key.")] + public void DisappearsOnWinKeyRelease() + { + PressWinKey(); + Thread.Sleep(TimeSpan.FromSeconds(2)); + WindowsElement shortcutHelperWindow; + try + { + shortcutHelperWindow = session.FindElementByXPath("/Pane[@ClassName=\"#32769\"]/Pane[@ClassName=\"PToyD2DPopup\"]"); + Assert.IsNotNull(shortcutHelperWindow); + } + catch (InvalidOperationException ex) + { + // Not the exception we wanted to catch here. + Assert.Fail("Shortcut Guide not found"); + } + ReleaseWinKey(); + Thread.Sleep(TimeSpan.FromSeconds(0.5)); + shortcutHelperWindow = session.FindElementByXPath("/Pane[@ClassName=\"#32769\"]/Pane[@ClassName=\"PToyD2DPopup\"]"); + } + [TestMethod] + public void DoesNotBlockStartMenuOnShortPress() + { + PressWinKey(); + Thread.Sleep(TimeSpan.FromSeconds(0.4)); + // FindElementByClassName will be faster than using with XPath. + WindowsElement shortcutHelperWindow = session.FindElementByClassName("PToyD2DPopup"); + Assert.IsNotNull(shortcutHelperWindow); + ReleaseWinKey(); + Thread.Sleep(TimeSpan.FromSeconds(0.5)); + 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(); + Thread.Sleep(TimeSpan.FromSeconds(2)); + try + { + // FindElementByClassName will be faster than using with XPath. + WindowsElement shortcutHelperWindow = session.FindElementByClassName("PToyD2DPopup"); + Assert.IsNotNull(shortcutHelperWindow); + } catch (InvalidOperationException ex) + { + // Not the exception we wanted to catch here. + Assert.Fail("Shortcut Guide not found"); + } + ReleaseWinKey(); + Thread.Sleep(TimeSpan.FromSeconds(0.5)); + WindowsElement startMenuWindow = session.FindElementByXPath("/Pane[@ClassName=\"#32769\"]/Window[@Name=\"Start\"]"); + } + [ClassInitialize] + public static void ClassInitialize(TestContext context) + { + Setup(context); + } + [ClassCleanup] + public static void ClassCleanup() + { + 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 ex) + { + //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) + { + startMenuSession.Keyboard.SendKeys(OpenQA.Selenium.Keys.Escape + OpenQA.Selenium.Keys.Escape); + 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/packages.config b/src/tests/win-app-driver/packages.config new file mode 100644 index 000000000000..179155f5db7d --- /dev/null +++ b/src/tests/win-app-driver/packages.config @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/src/tests/win-app-driver/win-app-driver.csproj b/src/tests/win-app-driver/win-app-driver.csproj new file mode 100644 index 000000000000..fd915e70ba3f --- /dev/null +++ b/src/tests/win-app-driver/win-app-driver.csproj @@ -0,0 +1,106 @@ + + + + + + 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}. + + + + + + + \ No newline at end of file From 280c6f44fdebd7bdfaa8ea9d273b5d2e1ca9344d Mon Sep 17 00:00:00 2001 From: Serafima Zykova Date: Thu, 27 Feb 2020 20:27:10 +0300 Subject: [PATCH 02/33] launch power toys for tests automatically --- src/tests/win-app-driver/PowerToysSession.cs | 48 +++++++++++++++++++- 1 file changed, 46 insertions(+), 2 deletions(-) diff --git a/src/tests/win-app-driver/PowerToysSession.cs b/src/tests/win-app-driver/PowerToysSession.cs index 7d7a3d1b0c89..7dd87cc35a73 100644 --- a/src/tests/win-app-driver/PowerToysSession.cs +++ b/src/tests/win-app-driver/PowerToysSession.cs @@ -2,7 +2,6 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; using OpenQA.Selenium.Appium; using OpenQA.Selenium.Appium.Windows; -using OpenQA.Selenium.Remote; using OpenQA.Selenium; namespace PowerToysTests @@ -11,10 +10,11 @@ public class PowerToysSession { protected const string WindowsApplicationDriverUrl = "http://127.0.0.1:4723"; protected static WindowsDriver session; + protected static bool isPowerToysLaunched = false; + protected static WindowsElement trayButton; public static void Setup(TestContext context) { - // TODO: Launch PowerToys application if it is not yet launched if (session == null) { // Create a new Desktop session to use PowerToys. @@ -23,6 +23,14 @@ public static void Setup(TestContext context) appiumOptions.AddAdditionalCapability("app", "Root"); session = new WindowsDriver(new Uri(WindowsApplicationDriverUrl), appiumOptions); Assert.IsNotNull(session); + + trayButton = session.FindElementByAccessibilityId("1502"); + + isPowerToysLaunched = CheckPowerToysLaunched(); + if (!isPowerToysLaunched) + { + LaunchPowerToys(); + } } } @@ -36,5 +44,41 @@ public static void TearDown() } } + private static bool CheckPowerToysLaunched() + { + trayButton.Click(); + bool isLaunched = false; + + try + { + WindowsElement pt = session.FindElementByName("PowerToys"); + isLaunched = (pt != null); + } + catch(OpenQA.Selenium.WebDriverException) + { + //PowerToys not found + } + + trayButton.Click(); //close + return isLaunched; + } + + public static void LaunchPowerToys() + { + try + { + AppiumOptions opts = new AppiumOptions(); + opts.PlatformName = "Windows"; + opts.AddAdditionalCapability("app", "Microsoft.PowerToys_8wekyb3d8bbwe!PowerToys"); + + WindowsDriver driver = new WindowsDriver(new Uri(WindowsApplicationDriverUrl), opts); + Assert.IsNotNull(driver); + driver.LaunchApp(); + } + catch (OpenQA.Selenium.WebDriverException) + { + //exception could be thrown even if app launched successfully + } + } } } From 7cf26ab31bf9515204c0c9c26983591c8818f29b Mon Sep 17 00:00:00 2001 From: Serafima Zykova Date: Thu, 27 Feb 2020 20:27:52 +0300 Subject: [PATCH 03/33] open and close settings methods added --- src/tests/win-app-driver/PowerToysSession.cs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/tests/win-app-driver/PowerToysSession.cs b/src/tests/win-app-driver/PowerToysSession.cs index 7dd87cc35a73..48240e9a9249 100644 --- a/src/tests/win-app-driver/PowerToysSession.cs +++ b/src/tests/win-app-driver/PowerToysSession.cs @@ -44,6 +44,19 @@ public static void TearDown() } } + public void OpenSettings() + { + trayButton.Click(); + session.FindElementByName("PowerToys").Click(); + trayButton.Click(); + } + + public void CloseSettings() + { + WindowsElement settings = session.FindElementByName("PowerToys Settings"); + settings.SendKeys(Keys.Alt + Keys.F4); + } + private static bool CheckPowerToysLaunched() { trayButton.Click(); From 4ce22fec999d605ff909c1e2552fbc19e4f9c7ac Mon Sep 17 00:00:00 2001 From: Serafima Zykova Date: Thu, 27 Feb 2020 20:28:27 +0300 Subject: [PATCH 04/33] tests for settings opening and app exit --- .../win-app-driver/PowerToysTrayTests.cs | 116 ++++++++++++++++++ .../win-app-driver/win-app-driver.csproj | 1 + 2 files changed, 117 insertions(+) create mode 100644 src/tests/win-app-driver/PowerToysTrayTests.cs diff --git a/src/tests/win-app-driver/PowerToysTrayTests.cs b/src/tests/win-app-driver/PowerToysTrayTests.cs new file mode 100644 index 000000000000..542de481ae94 --- /dev/null +++ b/src/tests/win-app-driver/PowerToysTrayTests.cs @@ -0,0 +1,116 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using OpenQA.Selenium.Appium.Windows; +using System.Threading; + +namespace PowerToysTests +{ + [TestClass] + public class PowerToysTrayTests : PowerToysSession + { + private bool isSettingsOpened; + private bool isTrayOpened; + + [TestMethod] + public void SettingsOpen() + { + OpenSettings(); + Thread.Sleep(TimeSpan.FromSeconds(0.5)); + + //check settings window opened + WindowsElement settingsWindow = session.FindElementByName("PowerToys Settings"); + Assert.IsNotNull(settingsWindow); + + isSettingsOpened = true; + } + + [TestMethod] + public void SettingsOpenWithContextMenu() + { + //open tray + trayButton.Click(); + isTrayOpened = true; + + //open PowerToys context menu + WindowsElement pt = session.FindElementByName("PowerToys"); + Assert.IsNotNull(pt); + + session.Mouse.ContextClick(pt.Coordinates); + Thread.Sleep(TimeSpan.FromSeconds(0.5)); + + //open settings + session.FindElementByXPath("//MenuItem[@AutomationId=\"40002\"]").Click(); + Thread.Sleep(TimeSpan.FromSeconds(0.5)); + + //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; + + WindowsElement pt = session.FindElementByName("PowerToys"); + Assert.IsNotNull(pt); + + session.Mouse.ContextClick(pt.Coordinates); + Thread.Sleep(TimeSpan.FromSeconds(0.5)); + + //exit + session.FindElementByXPath("//MenuItem[@AutomationId=\"40001\"]").Click(); + Thread.Sleep(TimeSpan.FromSeconds(0.5)); + + //check PowerToys exited + try + { + Assert.IsNull(session.FindElementByName("PowerToys")); + } + catch (OpenQA.Selenium.WebDriverException) + { + //expected, PowerToys shouldn't be here + } + + LaunchPowerToys(); + Thread.Sleep(TimeSpan.FromSeconds(0.5)); + } + + [ClassInitialize] + public static void ClassInitialize(TestContext context) + { + Setup(context); + } + + [ClassCleanup] + public static void ClassCleanup() + { + 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/win-app-driver.csproj b/src/tests/win-app-driver/win-app-driver.csproj index fd915e70ba3f..63daa388ea4b 100644 --- a/src/tests/win-app-driver/win-app-driver.csproj +++ b/src/tests/win-app-driver/win-app-driver.csproj @@ -83,6 +83,7 @@ + From 41a9e9b81e35f1feeafc0fa053e9440dbb753628 Mon Sep 17 00:00:00 2001 From: Serafima Zykova Date: Mon, 2 Mar 2020 18:13:03 +0300 Subject: [PATCH 05/33] added FancyZones tests --- src/tests/win-app-driver/FancyZonesTests.cs | 89 +++++++++++++++++++ .../win-app-driver/win-app-driver.csproj | 1 + 2 files changed, 90 insertions(+) create mode 100644 src/tests/win-app-driver/FancyZonesTests.cs diff --git a/src/tests/win-app-driver/FancyZonesTests.cs b/src/tests/win-app-driver/FancyZonesTests.cs new file mode 100644 index 000000000000..87b25b3ff7ad --- /dev/null +++ b/src/tests/win-app-driver/FancyZonesTests.cs @@ -0,0 +1,89 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using OpenQA.Selenium; +using OpenQA.Selenium.Appium.Windows; +using System.Threading; + +namespace PowerToysTests +{ + [TestClass] + public class FancyZonesTests : PowerToysSession + { + private void OpenFancyZonesSettings() + { + WindowsElement fzMenuButton = session.FindElementByXPath("//Button[@Name=\"FancyZones\"]"); + Assert.IsNotNull(fzMenuButton); + fzMenuButton.Click(); + fzMenuButton.Click(); + + Thread.Sleep(TimeSpan.FromSeconds(0.5)); + } + + [TestMethod] + public void FancyZonesSettingsOpen() + { + WindowsElement fzMenuButton = session.FindElementByXPath("//Button[@Name=\"FancyZones\"]"); + Assert.IsNotNull(fzMenuButton); + fzMenuButton.Click(); + fzMenuButton.Click(); + Thread.Sleep(TimeSpan.FromSeconds(0.5)); + + WindowsElement fzTitle = session.FindElementByName("FancyZones Settings"); + Assert.IsNotNull(fzTitle); + } + + [TestMethod] + public void EditorOpen() + { + OpenFancyZonesSettings(); + + session.FindElementByXPath("//Button[@Name=\"Edit zones\"]").Click(); + Thread.Sleep(TimeSpan.FromSeconds(0.5)); + + WindowsElement editorWindow = session.FindElementByName("FancyZones Editor"); + Assert.IsNotNull(editorWindow); + } + + [ClassInitialize] + public static void ClassInitialize(TestContext context) + { + Setup(context); + } + + [ClassCleanup] + public static void ClassCleanup() + { + TearDown(); + } + + [TestInitialize] + public void TestInitialize() + { + OpenSettings(); + Thread.Sleep(TimeSpan.FromSeconds(0.5)); + + WindowsElement settingsWindow = session.FindElementByName("PowerToys Settings"); + settingsWindow.Click(); //set focus on window + } + + [TestCleanup] + public void TestCleanup() + { + try + { + WindowsElement editorWindow = session.FindElementByName("FancyZones Editor"); + if (editorWindow != null) + { + editorWindow.SendKeys(Keys.Alt + Keys.F4); + } + } + catch (OpenQA.Selenium.WebDriverException) + { + //editor window not found + } + + + CloseSettings(); + } + } +} diff --git a/src/tests/win-app-driver/win-app-driver.csproj b/src/tests/win-app-driver/win-app-driver.csproj index 63daa388ea4b..f954b91e07af 100644 --- a/src/tests/win-app-driver/win-app-driver.csproj +++ b/src/tests/win-app-driver/win-app-driver.csproj @@ -82,6 +82,7 @@ + From e9db2c8b58f71681f1ed5d06c3d207dd7d90189f Mon Sep 17 00:00:00 2001 From: Serafima Zykova Date: Mon, 2 Mar 2020 19:49:40 +0300 Subject: [PATCH 06/33] toggles double click tests --- src/tests/win-app-driver/FancyZonesTests.cs | 44 ++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/src/tests/win-app-driver/FancyZonesTests.cs b/src/tests/win-app-driver/FancyZonesTests.cs index 87b25b3ff7ad..71e0b7638bf4 100644 --- a/src/tests/win-app-driver/FancyZonesTests.cs +++ b/src/tests/win-app-driver/FancyZonesTests.cs @@ -1,4 +1,6 @@ -using System; +using System; +using System.IO; +using Newtonsoft.Json; using Microsoft.VisualStudio.TestTools.UnitTesting; using OpenQA.Selenium; using OpenQA.Selenium.Appium.Windows; @@ -9,6 +11,8 @@ namespace PowerToysTests [TestClass] public class FancyZonesTests : PowerToysSession { + private string settingsFile = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Microsoft/PowerToys/FancyZones/settings.json"); + private void OpenFancyZonesSettings() { WindowsElement fzMenuButton = session.FindElementByXPath("//Button[@Name=\"FancyZones\"]"); @@ -44,6 +48,44 @@ public void EditorOpen() Assert.IsNotNull(editorWindow); } + [TestMethod] + /* + * click each toggle twice, + * save changes, + * check if settings are unchanged after clicking save button + */ + [TestMethod] + public void TogglesDoubleClickSave() + { + OpenFancyZonesSettings(); + + WindowsElement saveButton = session.FindElementByName("Save"); + Assert.IsNotNull(saveButton); + string isEnabled = saveButton.GetAttribute("IsEnabled"); + Assert.AreEqual("False", isEnabled); + + string initialSettings = File.ReadAllText(settingsFile); + + for (int i = 37; i < 45; i++) + { + string toggleId = "Toggle" + i.ToString(); + WindowsElement toggle = session.FindElementByAccessibilityId(toggleId); + Assert.IsNotNull(toggle); + toggle.Click(); + toggle.Click(); + + isEnabled = saveButton.GetAttribute("IsEnabled"); + Assert.AreEqual("True", isEnabled); + + saveButton.Click(); + isEnabled = saveButton.GetAttribute("IsEnabled"); + Assert.AreEqual("False", isEnabled); + + string savedSettings = File.ReadAllText(settingsFile); + Assert.AreEqual(initialSettings, savedSettings); + } + } + [ClassInitialize] public static void ClassInitialize(TestContext context) { From 09ceaf3955340224402eae748d149ed0c549e947 Mon Sep 17 00:00:00 2001 From: Serafima Zykova Date: Tue, 3 Mar 2020 15:06:35 +0300 Subject: [PATCH 07/33] moved common function --- src/tests/win-app-driver/FancyZonesTests.cs | 6 +++--- src/tests/win-app-driver/PowerToysSession.cs | 6 ++++++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/tests/win-app-driver/FancyZonesTests.cs b/src/tests/win-app-driver/FancyZonesTests.cs index 71e0b7638bf4..7a51610f8c86 100644 --- a/src/tests/win-app-driver/FancyZonesTests.cs +++ b/src/tests/win-app-driver/FancyZonesTests.cs @@ -20,7 +20,7 @@ private void OpenFancyZonesSettings() fzMenuButton.Click(); fzMenuButton.Click(); - Thread.Sleep(TimeSpan.FromSeconds(0.5)); + ShortWait(); } [TestMethod] @@ -30,7 +30,7 @@ public void FancyZonesSettingsOpen() Assert.IsNotNull(fzMenuButton); fzMenuButton.Click(); fzMenuButton.Click(); - Thread.Sleep(TimeSpan.FromSeconds(0.5)); + ShortWait(); WindowsElement fzTitle = session.FindElementByName("FancyZones Settings"); Assert.IsNotNull(fzTitle); @@ -42,7 +42,7 @@ public void EditorOpen() OpenFancyZonesSettings(); session.FindElementByXPath("//Button[@Name=\"Edit zones\"]").Click(); - Thread.Sleep(TimeSpan.FromSeconds(0.5)); + ShortWait(); WindowsElement editorWindow = session.FindElementByName("FancyZones Editor"); Assert.IsNotNull(editorWindow); diff --git a/src/tests/win-app-driver/PowerToysSession.cs b/src/tests/win-app-driver/PowerToysSession.cs index 48240e9a9249..14dc9eccf44c 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.Threading; using Microsoft.VisualStudio.TestTools.UnitTesting; using OpenQA.Selenium.Appium; using OpenQA.Selenium.Appium.Windows; @@ -44,6 +45,11 @@ public static void TearDown() } } + public static void ShortWait() + { + Thread.Sleep(TimeSpan.FromSeconds(0.5)); + } + public void OpenSettings() { trayButton.Click(); From 7c14ab20881d9fb6df4e6640533359171ae21b9a Mon Sep 17 00:00:00 2001 From: Serafima Zykova Date: Tue, 3 Mar 2020 15:07:06 +0300 Subject: [PATCH 08/33] keep settings file unchanged after tests --- src/tests/win-app-driver/FancyZonesTests.cs | 26 ++++++++++----------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/tests/win-app-driver/FancyZonesTests.cs b/src/tests/win-app-driver/FancyZonesTests.cs index 7a51610f8c86..d5dd17224555 100644 --- a/src/tests/win-app-driver/FancyZonesTests.cs +++ b/src/tests/win-app-driver/FancyZonesTests.cs @@ -1,17 +1,18 @@ using System; using System.IO; -using Newtonsoft.Json; using Microsoft.VisualStudio.TestTools.UnitTesting; using OpenQA.Selenium; using OpenQA.Selenium.Appium.Windows; -using System.Threading; +using Newtonsoft.Json.Linq; namespace PowerToysTests { [TestClass] public class FancyZonesTests : PowerToysSession { - private string settingsFile = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Microsoft/PowerToys/FancyZones/settings.json"); + private string _settingsPath = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Microsoft/PowerToys/FancyZones/settings.json"); + private string _initialSettings; + private JObject _initialSettingsJson; private void OpenFancyZonesSettings() { @@ -64,8 +65,6 @@ public void TogglesDoubleClickSave() string isEnabled = saveButton.GetAttribute("IsEnabled"); Assert.AreEqual("False", isEnabled); - string initialSettings = File.ReadAllText(settingsFile); - for (int i = 37; i < 45; i++) { string toggleId = "Toggle" + i.ToString(); @@ -80,10 +79,11 @@ public void TogglesDoubleClickSave() saveButton.Click(); isEnabled = saveButton.GetAttribute("IsEnabled"); Assert.AreEqual("False", isEnabled); - - string savedSettings = File.ReadAllText(settingsFile); - Assert.AreEqual(initialSettings, savedSettings); } + + string savedSettings = File.ReadAllText(_settingsPath); + Assert.AreEqual(_initialSettings, savedSettings); + } } [ClassInitialize] @@ -101,11 +101,11 @@ public static void ClassCleanup() [TestInitialize] public void TestInitialize() { - OpenSettings(); - Thread.Sleep(TimeSpan.FromSeconds(0.5)); + _initialSettings = File.ReadAllText(_settingsPath); + _initialSettingsJson = JObject.Parse(_initialSettings); - WindowsElement settingsWindow = session.FindElementByName("PowerToys Settings"); - settingsWindow.Click(); //set focus on window + OpenSettings(); + ShortWait(); } [TestCleanup] @@ -123,9 +123,9 @@ public void TestCleanup() { //editor window not found } - CloseSettings(); + File.WriteAllText(_settingsPath, _initialSettings); } } } From 199b60c5cfb8384400905cb9f39ad71ec186a281 Mon Sep 17 00:00:00 2001 From: Serafima Zykova Date: Tue, 3 Mar 2020 15:08:07 +0300 Subject: [PATCH 09/33] toggles click tests --- src/tests/win-app-driver/FancyZonesTests.cs | 44 +++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/src/tests/win-app-driver/FancyZonesTests.cs b/src/tests/win-app-driver/FancyZonesTests.cs index d5dd17224555..8bade66dec0d 100644 --- a/src/tests/win-app-driver/FancyZonesTests.cs +++ b/src/tests/win-app-driver/FancyZonesTests.cs @@ -49,7 +49,51 @@ public void EditorOpen() Assert.IsNotNull(editorWindow); } + /* + * click each toggle, + * save changes, + * check if settings are changed after clicking save button + */ [TestMethod] + public void TogglesSingleClickSaveButtonTest() + { + OpenFancyZonesSettings(); + + WindowsElement saveButton = session.FindElementByName("Save"); + Assert.IsNotNull(saveButton); + string IsEnabled = saveButton.GetAttribute("IsEnabled"); + Assert.AreEqual("False", IsEnabled); + + for (int i = 37; i < 45; i++) + { + string toggleId = "Toggle" + i.ToString(); + WindowsElement toggle = session.FindElementByAccessibilityId(toggleId); + Assert.IsNotNull(toggle); + toggle.Click(); + + IsEnabled = saveButton.GetAttribute("IsEnabled"); + Assert.AreEqual("True", IsEnabled); + + saveButton.Click(); + IsEnabled = saveButton.GetAttribute("IsEnabled"); + Assert.AreEqual("False", IsEnabled); + } + + //check saved settings + JObject savedSettings = JObject.Parse(File.ReadAllText(_settingsPath)); + JObject savedProps = savedSettings["properties"].ToObject(); + JObject initialProps = _initialSettingsJson["properties"].ToObject(); + + Assert.AreNotEqual(initialProps["fancyzones_shiftDrag"].ToObject()["value"].Value(), savedProps["fancyzones_shiftDrag"].ToObject()["value"].Value()); + Assert.AreNotEqual(initialProps["fancyzones_overrideSnapHotkeys"].ToObject()["value"].Value(), savedProps["fancyzones_overrideSnapHotkeys"].ToObject()["value"].Value()); + Assert.AreNotEqual(initialProps["fancyzones_zoneSetChange_flashZones"].ToObject()["value"].Value(), savedProps["fancyzones_zoneSetChange_flashZones"].ToObject()["value"].Value()); + Assert.AreNotEqual(initialProps["fancyzones_displayChange_moveWindows"].ToObject()["value"].Value(), savedProps["fancyzones_displayChange_moveWindows"].ToObject()["value"].Value()); + Assert.AreNotEqual(initialProps["fancyzones_zoneSetChange_moveWindows"].ToObject()["value"].Value(), savedProps["fancyzones_zoneSetChange_moveWindows"].ToObject()["value"].Value()); + Assert.AreNotEqual(initialProps["fancyzones_virtualDesktopChange_moveWindows"].ToObject()["value"].Value(), savedProps["fancyzones_virtualDesktopChange_moveWindows"].ToObject()["value"].Value()); + Assert.AreNotEqual(initialProps["fancyzones_appLastZone_moveWindows"].ToObject()["value"].Value(), savedProps["fancyzones_appLastZone_moveWindows"].ToObject()["value"].Value()); + Assert.AreNotEqual(initialProps["use_cursorpos_editor_startupscreen"].ToObject()["value"].Value(), savedProps["use_cursorpos_editor_startupscreen"].ToObject()["value"].Value()); + } + /* * click each toggle twice, * save changes, From 576702b9582e0a91e76c27ba4f257ef65d751688 Mon Sep 17 00:00:00 2001 From: Serafima Zykova Date: Tue, 3 Mar 2020 18:23:41 +0300 Subject: [PATCH 10/33] opacity highlight input tests --- src/tests/win-app-driver/FancyZonesTests.cs | 134 +++++++++++++++++- .../win-app-driver/win-app-driver.csproj | 1 + 2 files changed, 129 insertions(+), 6 deletions(-) diff --git a/src/tests/win-app-driver/FancyZonesTests.cs b/src/tests/win-app-driver/FancyZonesTests.cs index 8bade66dec0d..177bddfce116 100644 --- a/src/tests/win-app-driver/FancyZonesTests.cs +++ b/src/tests/win-app-driver/FancyZonesTests.cs @@ -1,9 +1,10 @@ using System; using System.IO; +using System.Windows.Forms; using Microsoft.VisualStudio.TestTools.UnitTesting; -using OpenQA.Selenium; -using OpenQA.Selenium.Appium.Windows; using Newtonsoft.Json.Linq; +using OpenQA.Selenium.Appium.Windows; +using OpenQA.Selenium.Interactions; namespace PowerToysTests { @@ -23,6 +24,27 @@ private void OpenFancyZonesSettings() ShortWait(); } + + private void SaveAndCheckOpacitySettings(WindowsElement saveButton, WindowsElement editor, int expected) + { + Assert.AreEqual(expected.ToString() + "\r\n", editor.Text); + + saveButton.Click(); + ShortWait(); + + JObject savedSettings = JObject.Parse(File.ReadAllText(_settingsPath)); + JObject savedProps = savedSettings["properties"].ToObject(); + int value = savedProps["fancyzones_highlight_opacity"].ToObject()["value"].Value(); + 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 + } [TestMethod] public void FancyZonesSettingsOpen() @@ -128,6 +150,95 @@ public void TogglesDoubleClickSave() string savedSettings = File.ReadAllText(_settingsPath); Assert.AreEqual(_initialSettings, savedSettings); } + + [TestMethod] + public void HighlightOpacitySetValue() + { + OpenFancyZonesSettings(); + WindowsElement saveButton = session.FindElementByName("Save"); + Assert.IsNotNull(saveButton); + + WindowsElement editor = session.FindElementByName("Zone Highlight Opacity (%)"); + Assert.IsNotNull(editor); + + SetOpacity(editor, "50"); + SaveAndCheckOpacitySettings(saveButton, editor, 50); + + SetOpacity(editor, "-50"); + SaveAndCheckOpacitySettings(saveButton, editor, 0); + + SetOpacity(editor, "200"); + SaveAndCheckOpacitySettings(saveButton, editor, 100); + + //for invalid input values previously saved value expected + SetOpacity(editor, "asdf"); + SaveAndCheckOpacitySettings(saveButton, editor, 100); + + SetOpacity(editor, "*"); + SaveAndCheckOpacitySettings(saveButton, editor, 100); + + SetOpacity(editor, OpenQA.Selenium.Keys.Return); + SaveAndCheckOpacitySettings(saveButton, editor, 100); + + Clipboard.SetText("Hello, clipboard"); + SetOpacity(editor, OpenQA.Selenium.Keys.Control + "v"); + SaveAndCheckOpacitySettings(saveButton, editor, 100); + } + + [TestMethod] + public void HighlightOpacityIncreaseValue() + { + OpenFancyZonesSettings(); + WindowsElement saveButton = session.FindElementByName("Save"); + Assert.IsNotNull(saveButton); + + WindowsElement editor = session.FindElementByName("Zone Highlight Opacity (%)"); + Assert.IsNotNull(editor); + + SetOpacity(editor, "99"); + SaveAndCheckOpacitySettings(saveButton, 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(); + ShortWait(); + + action.Click().Perform(); + Assert.AreEqual("100\r\n", editor.Text); + SaveAndCheckOpacitySettings(saveButton, editor, 100); + + action.Click().Perform(); + Assert.AreEqual("100\r\n", editor.Text); + SaveAndCheckOpacitySettings(saveButton, editor, 100); + } + + [TestMethod] + public void HighlightOpacityDecreaseValue() + { + OpenFancyZonesSettings(); + WindowsElement saveButton = session.FindElementByName("Save"); + Assert.IsNotNull(saveButton); + + WindowsElement editor = session.FindElementByName("Zone Highlight Opacity (%)"); + Assert.IsNotNull(editor); + + SetOpacity(editor, "1"); + SaveAndCheckOpacitySettings(saveButton, 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(); + ShortWait(); + + action.Click().Perform(); + Assert.AreEqual("0\r\n", editor.Text); + SaveAndCheckOpacitySettings(saveButton, editor, 0); + + action.Click().Perform(); + Assert.AreEqual("0\r\n", editor.Text); + SaveAndCheckOpacitySettings(saveButton, editor, 0); } [ClassInitialize] @@ -145,8 +256,16 @@ public static void ClassCleanup() [TestInitialize] public void TestInitialize() { - _initialSettings = File.ReadAllText(_settingsPath); - _initialSettingsJson = JObject.Parse(_initialSettings); + try + { + _initialSettings = File.ReadAllText(_settingsPath); + _initialSettingsJson = JObject.Parse(_initialSettings); + } + catch (System.IO.FileNotFoundException) + { + _initialSettings = ""; + } + OpenSettings(); ShortWait(); @@ -160,7 +279,7 @@ public void TestCleanup() WindowsElement editorWindow = session.FindElementByName("FancyZones Editor"); if (editorWindow != null) { - editorWindow.SendKeys(Keys.Alt + Keys.F4); + editorWindow.SendKeys(OpenQA.Selenium.Keys.Alt + OpenQA.Selenium.Keys.F4); } } catch (OpenQA.Selenium.WebDriverException) @@ -169,7 +288,10 @@ public void TestCleanup() } CloseSettings(); - File.WriteAllText(_settingsPath, _initialSettings); + if (_initialSettings.Length > 0) + { + File.WriteAllText(_settingsPath, _initialSettings); + } } } } diff --git a/src/tests/win-app-driver/win-app-driver.csproj b/src/tests/win-app-driver/win-app-driver.csproj index f954b91e07af..a611b07d3e34 100644 --- a/src/tests/win-app-driver/win-app-driver.csproj +++ b/src/tests/win-app-driver/win-app-driver.csproj @@ -72,6 +72,7 @@ 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 From 5d4514f3d1311e93563a4535f50a649938c51978 Mon Sep 17 00:00:00 2001 From: Serafima Zykova Date: Tue, 3 Mar 2020 18:58:06 +0300 Subject: [PATCH 11/33] clear button test --- src/tests/win-app-driver/FancyZonesTests.cs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/tests/win-app-driver/FancyZonesTests.cs b/src/tests/win-app-driver/FancyZonesTests.cs index 177bddfce116..2fed4d17191d 100644 --- a/src/tests/win-app-driver/FancyZonesTests.cs +++ b/src/tests/win-app-driver/FancyZonesTests.cs @@ -241,6 +241,24 @@ public void HighlightOpacityDecreaseValue() SaveAndCheckOpacitySettings(saveButton, editor, 0); } + [TestMethod] + public void HighlightOpacityClearValueButton() + { + OpenFancyZonesSettings(); + WindowsElement editor = session.FindElementByName("Zone Highlight Opacity (%)"); + Assert.IsNotNull(editor); + + editor.Click(); //activate + OpenQA.Selenium.Appium.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); + } + [ClassInitialize] public static void ClassInitialize(TestContext context) { From c7bc6b3c4da98f7c0d59655bf9162bbf34a8f942 Mon Sep 17 00:00:00 2001 From: Serafima Zykova Date: Wed, 4 Mar 2020 16:47:49 +0300 Subject: [PATCH 12/33] refactoring --- src/tests/win-app-driver/FancyZonesTests.cs | 57 ++++++++++++--------- 1 file changed, 34 insertions(+), 23 deletions(-) diff --git a/src/tests/win-app-driver/FancyZonesTests.cs b/src/tests/win-app-driver/FancyZonesTests.cs index 2fed4d17191d..827c9fa25b25 100644 --- a/src/tests/win-app-driver/FancyZonesTests.cs +++ b/src/tests/win-app-driver/FancyZonesTests.cs @@ -11,16 +11,34 @@ namespace PowerToysTests [TestClass] public class FancyZonesTests : PowerToysSession { - private string _settingsPath = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Microsoft/PowerToys/FancyZones/settings.json"); + private string _settingsPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Microsoft/PowerToys/FancyZones/settings.json"); private string _initialSettings; private JObject _initialSettingsJson; + + private JObject getProperties() + { + JObject settings = JObject.Parse(File.ReadAllText(_settingsPath)); + return settings["properties"].ToObject(); + } + + 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 OpenFancyZonesSettings() { - WindowsElement fzMenuButton = session.FindElementByXPath("//Button[@Name=\"FancyZones\"]"); - Assert.IsNotNull(fzMenuButton); - fzMenuButton.Click(); - fzMenuButton.Click(); + WindowsElement fzNavigationButton = session.FindElementByXPath("//Button[@Name=\"FancyZones\"]"); + Assert.IsNotNull(fzNavigationButton); + + fzNavigationButton.Click(); + fzNavigationButton.Click(); ShortWait(); } @@ -32,9 +50,7 @@ private void SaveAndCheckOpacitySettings(WindowsElement saveButton, WindowsEleme saveButton.Click(); ShortWait(); - JObject savedSettings = JObject.Parse(File.ReadAllText(_settingsPath)); - JObject savedProps = savedSettings["properties"].ToObject(); - int value = savedProps["fancyzones_highlight_opacity"].ToObject()["value"].Value(); + int value = getPropertyValue("fancyzones_highlight_opacity"); Assert.AreEqual(expected, value); } @@ -49,11 +65,7 @@ private void SetOpacity(WindowsElement editor, string key) [TestMethod] public void FancyZonesSettingsOpen() { - WindowsElement fzMenuButton = session.FindElementByXPath("//Button[@Name=\"FancyZones\"]"); - Assert.IsNotNull(fzMenuButton); - fzMenuButton.Click(); - fzMenuButton.Click(); - ShortWait(); + OpenFancyZonesSettings(); WindowsElement fzTitle = session.FindElementByName("FancyZones Settings"); Assert.IsNotNull(fzTitle); @@ -102,18 +114,17 @@ public void TogglesSingleClickSaveButtonTest() } //check saved settings - JObject savedSettings = JObject.Parse(File.ReadAllText(_settingsPath)); - JObject savedProps = savedSettings["properties"].ToObject(); + JObject savedProps = getProperties(); JObject initialProps = _initialSettingsJson["properties"].ToObject(); - Assert.AreNotEqual(initialProps["fancyzones_shiftDrag"].ToObject()["value"].Value(), savedProps["fancyzones_shiftDrag"].ToObject()["value"].Value()); - Assert.AreNotEqual(initialProps["fancyzones_overrideSnapHotkeys"].ToObject()["value"].Value(), savedProps["fancyzones_overrideSnapHotkeys"].ToObject()["value"].Value()); - Assert.AreNotEqual(initialProps["fancyzones_zoneSetChange_flashZones"].ToObject()["value"].Value(), savedProps["fancyzones_zoneSetChange_flashZones"].ToObject()["value"].Value()); - Assert.AreNotEqual(initialProps["fancyzones_displayChange_moveWindows"].ToObject()["value"].Value(), savedProps["fancyzones_displayChange_moveWindows"].ToObject()["value"].Value()); - Assert.AreNotEqual(initialProps["fancyzones_zoneSetChange_moveWindows"].ToObject()["value"].Value(), savedProps["fancyzones_zoneSetChange_moveWindows"].ToObject()["value"].Value()); - Assert.AreNotEqual(initialProps["fancyzones_virtualDesktopChange_moveWindows"].ToObject()["value"].Value(), savedProps["fancyzones_virtualDesktopChange_moveWindows"].ToObject()["value"].Value()); - Assert.AreNotEqual(initialProps["fancyzones_appLastZone_moveWindows"].ToObject()["value"].Value(), savedProps["fancyzones_appLastZone_moveWindows"].ToObject()["value"].Value()); - Assert.AreNotEqual(initialProps["use_cursorpos_editor_startupscreen"].ToObject()["value"].Value(), savedProps["use_cursorpos_editor_startupscreen"].ToObject()["value"].Value()); + Assert.AreNotEqual(getPropertyValue(initialProps, "fancyzones_shiftDrag"), getPropertyValue(savedProps, "fancyzones_shiftDrag")); + Assert.AreNotEqual(getPropertyValue(initialProps, "fancyzones_overrideSnapHotkeys"), getPropertyValue(savedProps, "fancyzones_overrideSnapHotkeys")); + Assert.AreNotEqual(getPropertyValue(initialProps, "fancyzones_zoneSetChange_flashZones"), getPropertyValue(savedProps, "fancyzones_zoneSetChange_flashZones")); + Assert.AreNotEqual(getPropertyValue(initialProps, "fancyzones_displayChange_moveWindows"), getPropertyValue(savedProps, "fancyzones_displayChange_moveWindows")); + Assert.AreNotEqual(getPropertyValue(initialProps, "fancyzones_zoneSetChange_moveWindows"), getPropertyValue(savedProps, "fancyzones_zoneSetChange_moveWindows")); + Assert.AreNotEqual(getPropertyValue(initialProps, "fancyzones_virtualDesktopChange_moveWindows"), getPropertyValue(savedProps, "fancyzones_virtualDesktopChange_moveWindows")); + Assert.AreNotEqual(getPropertyValue(initialProps, "fancyzones_appLastZone_moveWindows"), getPropertyValue(savedProps, "fancyzones_appLastZone_moveWindows")); + Assert.AreNotEqual(getPropertyValue(initialProps, "use_cursorpos_editor_startupscreen"), getPropertyValue(savedProps, "use_cursorpos_editor_startupscreen")); } /* From 413052b147cc6455d9c27276071972c2fdd4c04b Mon Sep 17 00:00:00 2001 From: Serafima Zykova Date: Wed, 4 Mar 2020 16:48:06 +0300 Subject: [PATCH 13/33] test color sliders --- src/tests/win-app-driver/FancyZonesTests.cs | 67 +++++++++++++++++++++ 1 file changed, 67 insertions(+) diff --git a/src/tests/win-app-driver/FancyZonesTests.cs b/src/tests/win-app-driver/FancyZonesTests.cs index 827c9fa25b25..bf8ac68182b4 100644 --- a/src/tests/win-app-driver/FancyZonesTests.cs +++ b/src/tests/win-app-driver/FancyZonesTests.cs @@ -270,6 +270,73 @@ public void HighlightOpacityClearValueButton() Assert.AreEqual("\r\n", editor.Text); } + [TestMethod] + public void HighlightColorSliders() + { + OpenFancyZonesSettings(); + + WindowsElement saveButton = session.FindElementByName("Save"); + Assert.IsNotNull(saveButton); + + WindowsElement powerToysWindow = session.FindElementByXPath("//Window[@Name=\"PowerToys Settings\"]"); + + new Actions(session).MoveByOffset(powerToysWindow.Rect.X + powerToysWindow.Rect.Width / 2 - 100, powerToysWindow.Rect.Y).Click() + .SendKeys(OpenQA.Selenium.Keys.PageDown + OpenQA.Selenium.Keys.PageDown).Perform(); + + WindowsElement saturationAndBrightness = session.FindElementByName("Saturation and brightness"); + WindowsElement hue = session.FindElementByName("Hue"); + WindowsElement hex = session.FindElementByAccessibilityId("TextField54"); + WindowsElement red = session.FindElementByAccessibilityId("TextField57"); + WindowsElement green = session.FindElementByAccessibilityId("TextField60"); + WindowsElement blue = session.FindElementByAccessibilityId("TextField63"); + + Assert.IsNotNull(saturationAndBrightness); + Assert.IsNotNull(hue); + Assert.IsNotNull(hex); + Assert.IsNotNull(red); + Assert.IsNotNull(green); + Assert.IsNotNull(blue); + + 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 / 2).Click().Perform(); + ShortWait(); + + 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); + + saveButton.Click(); + ShortWait(); + Assert.AreEqual("#000000", getPropertyValue("fancyzones_zoneHighlightColor")); + + //white in left corner + new Actions(session).MoveToElement(saturationAndBrightness).ClickAndHold().MoveByOffset(-(satRect.Width/2), -(satRect.Height / 2)).Click().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); + + saveButton.Click(); + ShortWait(); + Assert.AreEqual("#ffffff", getPropertyValue("fancyzones_zoneHighlightColor")); + + //color in right corner + new Actions(session).MoveToElement(saturationAndBrightness).ClickAndHold().MoveByOffset((satRect.Width / 2), -(satRect.Height / 2)).Click() + .MoveToElement(hue).ClickAndHold().MoveByOffset(-(hueRect.Width / 2), 0).Click().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); + + saveButton.Click(); + ShortWait(); + Assert.AreEqual("#ff0000", getPropertyValue("fancyzones_zoneHighlightColor")); + } + [ClassInitialize] public static void ClassInitialize(TestContext context) { From 6d01de5f038b6799da5b0cab4da25150d195f446 Mon Sep 17 00:00:00 2001 From: Serafima Zykova Date: Wed, 4 Mar 2020 18:56:02 +0300 Subject: [PATCH 14/33] test color inputs --- src/tests/win-app-driver/FancyZonesTests.cs | 148 +++++++++++++++++++- 1 file changed, 143 insertions(+), 5 deletions(-) diff --git a/src/tests/win-app-driver/FancyZonesTests.cs b/src/tests/win-app-driver/FancyZonesTests.cs index bf8ac68182b4..20cf3e74d651 100644 --- a/src/tests/win-app-driver/FancyZonesTests.cs +++ b/src/tests/win-app-driver/FancyZonesTests.cs @@ -43,6 +43,13 @@ private void OpenFancyZonesSettings() ShortWait(); } + private void ScrollDown() + { + WindowsElement powerToysWindow = session.FindElementByXPath("//Window[@Name=\"PowerToys Settings\"]"); + new Actions(session).MoveByOffset(powerToysWindow.Rect.X + powerToysWindow.Rect.Width / 2 - 100, powerToysWindow.Rect.Y).Click() + .SendKeys(OpenQA.Selenium.Keys.PageDown + OpenQA.Selenium.Keys.PageDown).Perform(); + } + private void SaveAndCheckOpacitySettings(WindowsElement saveButton, WindowsElement editor, int expected) { Assert.AreEqual(expected.ToString() + "\r\n", editor.Text); @@ -62,6 +69,55 @@ private void SetOpacity(WindowsElement editor, string key) editor.SendKeys(OpenQA.Selenium.Keys.Enter); //confirm changes } + private void TestRgbInput(string name) + { + WindowsElement colorInput = session.FindElementByAccessibilityId(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); + } + [TestMethod] public void FancyZonesSettingsOpen() { @@ -271,17 +327,14 @@ public void HighlightOpacityClearValueButton() } [TestMethod] - public void HighlightColorSliders() + public void HighlightColorSlidersTest() { OpenFancyZonesSettings(); WindowsElement saveButton = session.FindElementByName("Save"); Assert.IsNotNull(saveButton); - WindowsElement powerToysWindow = session.FindElementByXPath("//Window[@Name=\"PowerToys Settings\"]"); - - new Actions(session).MoveByOffset(powerToysWindow.Rect.X + powerToysWindow.Rect.Width / 2 - 100, powerToysWindow.Rect.Y).Click() - .SendKeys(OpenQA.Selenium.Keys.PageDown + OpenQA.Selenium.Keys.PageDown).Perform(); + ScrollDown(); WindowsElement saturationAndBrightness = session.FindElementByName("Saturation and brightness"); WindowsElement hue = session.FindElementByName("Hue"); @@ -337,6 +390,91 @@ public void HighlightColorSliders() Assert.AreEqual("#ff0000", getPropertyValue("fancyzones_zoneHighlightColor")); } + [TestMethod] + public void HighlightRGBInputsTest() + { + OpenFancyZonesSettings(); + ScrollDown(); + + TestRgbInput("TextField57"); //red + TestRgbInput("TextField60"); //green + TestRgbInput("TextField63"); //blue + + session.FindElementByName("Save").Click(); + } + + [TestMethod] + public void HighlightHexInputTest() + { + OpenFancyZonesSettings(); + ScrollDown(); + + WindowsElement hexInput = session.FindElementByAccessibilityId("TextField54"); + 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); + + session.FindElementByName("Save").Click(); + } + + [TestMethod] + public void HighlightColorTest() + { + OpenFancyZonesSettings(); + ScrollDown(); + + WindowsElement saturationAndBrightness = session.FindElementByName("Saturation and brightness"); + WindowsElement hue = session.FindElementByName("Hue"); + WindowsElement hex = session.FindElementByAccessibilityId("TextField54"); + + 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); + + session.FindElementByName("Save").Click(); + ShortWait(); + Assert.AreEqual("#63c99a", getPropertyValue("fancyzones_zoneHighlightColor")); + } + [ClassInitialize] public static void ClassInitialize(TestContext context) { From b66840a0f45ba45fbcdf40a5b2fa67873fe37c95 Mon Sep 17 00:00:00 2001 From: Serafima Zykova Date: Thu, 5 Mar 2020 19:09:25 +0300 Subject: [PATCH 15/33] refactoring --- ...nesTests.cs => FancyZonesSettingsTests.cs} | 189 ++++++++---------- src/tests/win-app-driver/PowerToysSession.cs | 4 +- .../win-app-driver/win-app-driver.csproj | 2 +- 3 files changed, 83 insertions(+), 112 deletions(-) rename src/tests/win-app-driver/{FancyZonesTests.cs => FancyZonesSettingsTests.cs} (81%) diff --git a/src/tests/win-app-driver/FancyZonesTests.cs b/src/tests/win-app-driver/FancyZonesSettingsTests.cs similarity index 81% rename from src/tests/win-app-driver/FancyZonesTests.cs rename to src/tests/win-app-driver/FancyZonesSettingsTests.cs index 20cf3e74d651..1fe7f9b271af 100644 --- a/src/tests/win-app-driver/FancyZonesTests.cs +++ b/src/tests/win-app-driver/FancyZonesSettingsTests.cs @@ -3,18 +3,34 @@ 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 { [TestClass] - public class FancyZonesTests : PowerToysSession + public class FancyZonesSettingsTests : PowerToysSession { private string _settingsPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Microsoft/PowerToys/FancyZones/settings.json"); private string _initialSettings; private JObject _initialSettingsJson; - + + private static WindowsElement _saveButton; + private static Actions _scrollDown; + private static Actions _scrollUp; + + private static void OpenFancyZonesSettings() + { + WindowsElement fzNavigationButton = session.FindElementByXPath("//Button[@Name=\"FancyZones\"]"); + Assert.IsNotNull(fzNavigationButton); + + fzNavigationButton.Click(); + fzNavigationButton.Click(); + + ShortWait(); + } + private JObject getProperties() { JObject settings = JObject.Parse(File.ReadAllText(_settingsPath)); @@ -31,30 +47,33 @@ private T getPropertyValue(JObject properties, string propertyName) { return properties[propertyName].ToObject()["value"].Value(); } - - private void OpenFancyZonesSettings() + + private void ScrollDown() { - WindowsElement fzNavigationButton = session.FindElementByXPath("//Button[@Name=\"FancyZones\"]"); - Assert.IsNotNull(fzNavigationButton); - - fzNavigationButton.Click(); - fzNavigationButton.Click(); + _scrollDown.Perform(); + } - ShortWait(); + private void ScrollUp() + { + _scrollUp.Perform(); } - - private void ScrollDown() + + private void SaveChanges() { - WindowsElement powerToysWindow = session.FindElementByXPath("//Window[@Name=\"PowerToys Settings\"]"); - new Actions(session).MoveByOffset(powerToysWindow.Rect.X + powerToysWindow.Rect.Width / 2 - 100, powerToysWindow.Rect.Y).Click() - .SendKeys(OpenQA.Selenium.Keys.PageDown + OpenQA.Selenium.Keys.PageDown).Perform(); + string isEnabled = _saveButton.GetAttribute("IsEnabled"); + Assert.AreEqual("True", isEnabled); + + _saveButton.Click(); + + isEnabled = _saveButton.GetAttribute("IsEnabled"); + Assert.AreEqual("False", isEnabled); } - private void SaveAndCheckOpacitySettings(WindowsElement saveButton, WindowsElement editor, int expected) + private void SaveAndCheckOpacitySettings(WindowsElement editor, int expected) { Assert.AreEqual(expected.ToString() + "\r\n", editor.Text); - saveButton.Click(); + SaveChanges(); ShortWait(); int value = getPropertyValue("fancyzones_highlight_opacity"); @@ -121,24 +140,22 @@ private void TestRgbInput(string name) [TestMethod] public void FancyZonesSettingsOpen() { - OpenFancyZonesSettings(); - WindowsElement fzTitle = session.FindElementByName("FancyZones Settings"); Assert.IsNotNull(fzTitle); } - + /* [TestMethod] public void EditorOpen() { - OpenFancyZonesSettings(); - session.FindElementByXPath("//Button[@Name=\"Edit zones\"]").Click(); ShortWait(); WindowsElement editorWindow = session.FindElementByName("FancyZones Editor"); Assert.IsNotNull(editorWindow); - } + editorWindow.SendKeys(OpenQA.Selenium.Keys.Alt + OpenQA.Selenium.Keys.F4); + } + */ /* * click each toggle, * save changes, @@ -147,13 +164,6 @@ public void EditorOpen() [TestMethod] public void TogglesSingleClickSaveButtonTest() { - OpenFancyZonesSettings(); - - WindowsElement saveButton = session.FindElementByName("Save"); - Assert.IsNotNull(saveButton); - string IsEnabled = saveButton.GetAttribute("IsEnabled"); - Assert.AreEqual("False", IsEnabled); - for (int i = 37; i < 45; i++) { string toggleId = "Toggle" + i.ToString(); @@ -161,12 +171,7 @@ public void TogglesSingleClickSaveButtonTest() Assert.IsNotNull(toggle); toggle.Click(); - IsEnabled = saveButton.GetAttribute("IsEnabled"); - Assert.AreEqual("True", IsEnabled); - - saveButton.Click(); - IsEnabled = saveButton.GetAttribute("IsEnabled"); - Assert.AreEqual("False", IsEnabled); + SaveChanges(); } //check saved settings @@ -191,13 +196,6 @@ public void TogglesSingleClickSaveButtonTest() [TestMethod] public void TogglesDoubleClickSave() { - OpenFancyZonesSettings(); - - WindowsElement saveButton = session.FindElementByName("Save"); - Assert.IsNotNull(saveButton); - string isEnabled = saveButton.GetAttribute("IsEnabled"); - Assert.AreEqual("False", isEnabled); - for (int i = 37; i < 45; i++) { string toggleId = "Toggle" + i.ToString(); @@ -206,12 +204,7 @@ public void TogglesDoubleClickSave() toggle.Click(); toggle.Click(); - isEnabled = saveButton.GetAttribute("IsEnabled"); - Assert.AreEqual("True", isEnabled); - - saveButton.Click(); - isEnabled = saveButton.GetAttribute("IsEnabled"); - Assert.AreEqual("False", isEnabled); + SaveChanges(); } string savedSettings = File.ReadAllText(_settingsPath); @@ -221,49 +214,41 @@ public void TogglesDoubleClickSave() [TestMethod] public void HighlightOpacitySetValue() { - OpenFancyZonesSettings(); - WindowsElement saveButton = session.FindElementByName("Save"); - Assert.IsNotNull(saveButton); - WindowsElement editor = session.FindElementByName("Zone Highlight Opacity (%)"); Assert.IsNotNull(editor); SetOpacity(editor, "50"); - SaveAndCheckOpacitySettings(saveButton, editor, 50); + SaveAndCheckOpacitySettings(editor, 50); SetOpacity(editor, "-50"); - SaveAndCheckOpacitySettings(saveButton, editor, 0); + SaveAndCheckOpacitySettings(editor, 0); SetOpacity(editor, "200"); - SaveAndCheckOpacitySettings(saveButton, editor, 100); + SaveAndCheckOpacitySettings(editor, 100); //for invalid input values previously saved value expected SetOpacity(editor, "asdf"); - SaveAndCheckOpacitySettings(saveButton, editor, 100); + SaveAndCheckOpacitySettings(editor, 100); SetOpacity(editor, "*"); - SaveAndCheckOpacitySettings(saveButton, editor, 100); + SaveAndCheckOpacitySettings(editor, 100); SetOpacity(editor, OpenQA.Selenium.Keys.Return); - SaveAndCheckOpacitySettings(saveButton, editor, 100); + SaveAndCheckOpacitySettings(editor, 100); Clipboard.SetText("Hello, clipboard"); SetOpacity(editor, OpenQA.Selenium.Keys.Control + "v"); - SaveAndCheckOpacitySettings(saveButton, editor, 100); + SaveAndCheckOpacitySettings(editor, 100); } [TestMethod] public void HighlightOpacityIncreaseValue() { - OpenFancyZonesSettings(); - WindowsElement saveButton = session.FindElementByName("Save"); - Assert.IsNotNull(saveButton); - WindowsElement editor = session.FindElementByName("Zone Highlight Opacity (%)"); Assert.IsNotNull(editor); SetOpacity(editor, "99"); - SaveAndCheckOpacitySettings(saveButton, editor, 99); + SaveAndCheckOpacitySettings(editor, 99); System.Drawing.Rectangle editorRect = editor.Rect; @@ -273,25 +258,22 @@ public void HighlightOpacityIncreaseValue() action.Click().Perform(); Assert.AreEqual("100\r\n", editor.Text); - SaveAndCheckOpacitySettings(saveButton, editor, 100); + SaveAndCheckOpacitySettings(editor, 100); action.Click().Perform(); Assert.AreEqual("100\r\n", editor.Text); - SaveAndCheckOpacitySettings(saveButton, editor, 100); + SaveAndCheckOpacitySettings(editor, 100); } [TestMethod] public void HighlightOpacityDecreaseValue() { - OpenFancyZonesSettings(); - WindowsElement saveButton = session.FindElementByName("Save"); - Assert.IsNotNull(saveButton); - + WindowsElement editor = session.FindElementByName("Zone Highlight Opacity (%)"); Assert.IsNotNull(editor); SetOpacity(editor, "1"); - SaveAndCheckOpacitySettings(saveButton, editor, 1); + SaveAndCheckOpacitySettings(editor, 1); System.Drawing.Rectangle editorRect = editor.Rect; @@ -301,22 +283,21 @@ public void HighlightOpacityDecreaseValue() action.Click().Perform(); Assert.AreEqual("0\r\n", editor.Text); - SaveAndCheckOpacitySettings(saveButton, editor, 0); + SaveAndCheckOpacitySettings(editor, 0); action.Click().Perform(); Assert.AreEqual("0\r\n", editor.Text); - SaveAndCheckOpacitySettings(saveButton, editor, 0); + SaveAndCheckOpacitySettings(editor, 0); } [TestMethod] public void HighlightOpacityClearValueButton() { - OpenFancyZonesSettings(); WindowsElement editor = session.FindElementByName("Zone Highlight Opacity (%)"); Assert.IsNotNull(editor); editor.Click(); //activate - OpenQA.Selenium.Appium.AppiumWebElement clearButton = editor.FindElementByName("Clear value"); + AppiumWebElement clearButton = editor.FindElementByName("Clear value"); Assert.IsNotNull(clearButton); /*element is not pointer- or keyboard interactable.*/ @@ -329,11 +310,6 @@ public void HighlightOpacityClearValueButton() [TestMethod] public void HighlightColorSlidersTest() { - OpenFancyZonesSettings(); - - WindowsElement saveButton = session.FindElementByName("Save"); - Assert.IsNotNull(saveButton); - ScrollDown(); WindowsElement saturationAndBrightness = session.FindElementByName("Saturation and brightness"); @@ -362,7 +338,7 @@ public void HighlightColorSlidersTest() Assert.AreEqual("0\r\n", blue.Text); Assert.AreEqual("000000\r\n", hex.Text); - saveButton.Click(); + SaveChanges(); ShortWait(); Assert.AreEqual("#000000", getPropertyValue("fancyzones_zoneHighlightColor")); @@ -373,7 +349,7 @@ public void HighlightColorSlidersTest() Assert.AreEqual("255\r\n", blue.Text); Assert.AreEqual("ffffff\r\n", hex.Text); - saveButton.Click(); + SaveChanges(); ShortWait(); Assert.AreEqual("#ffffff", getPropertyValue("fancyzones_zoneHighlightColor")); @@ -385,7 +361,7 @@ public void HighlightColorSlidersTest() Assert.AreEqual("0\r\n", blue.Text); Assert.AreEqual("ff0000\r\n", hex.Text); - saveButton.Click(); + SaveChanges(); ShortWait(); Assert.AreEqual("#ff0000", getPropertyValue("fancyzones_zoneHighlightColor")); } @@ -393,20 +369,16 @@ public void HighlightColorSlidersTest() [TestMethod] public void HighlightRGBInputsTest() { - OpenFancyZonesSettings(); ScrollDown(); TestRgbInput("TextField57"); //red TestRgbInput("TextField60"); //green TestRgbInput("TextField63"); //blue - - session.FindElementByName("Save").Click(); } [TestMethod] public void HighlightHexInputTest() { - OpenFancyZonesSettings(); ScrollDown(); WindowsElement hexInput = session.FindElementByAccessibilityId("TextField54"); @@ -445,14 +417,11 @@ public void HighlightHexInputTest() hexInput.SendKeys("1234"); new Actions(session).MoveToElement(hexInput).MoveByOffset(0, hexInput.Rect.Height).Click().Perform(); Assert.AreEqual("112233\r\n", hexInput.Text); - - session.FindElementByName("Save").Click(); } [TestMethod] public void HighlightColorTest() { - OpenFancyZonesSettings(); ScrollDown(); WindowsElement saturationAndBrightness = session.FindElementByName("Saturation and brightness"); @@ -470,7 +439,7 @@ public void HighlightColorTest() Assert.AreEqual("Saturation 51 brightness 79", saturationAndBrightness.Text); Assert.AreEqual("152", hue.Text); - session.FindElementByName("Save").Click(); + SaveChanges(); ShortWait(); Assert.AreEqual("#63c99a", getPropertyValue("fancyzones_zoneHighlightColor")); } @@ -479,11 +448,29 @@ public void HighlightColorTest() public static void ClassInitialize(TestContext context) { Setup(context); + + OpenSettings(); + ShortWait(); + + OpenFancyZonesSettings(); + + _saveButton = session.FindElementByName("Save"); + Assert.IsNotNull(_saveButton); + + WindowsElement powerToysWindow = session.FindElementByXPath("//Window[@Name=\"PowerToys Settings\"]"); + Assert.IsNotNull(powerToysWindow); + _scrollUp = new Actions(session).MoveToElement(_saveButton).MoveByOffset(0, _saveButton.Rect.Height).ContextClick() + .SendKeys(OpenQA.Selenium.Keys.PageUp + OpenQA.Selenium.Keys.PageUp); + Assert.IsNotNull(_scrollUp); + _scrollDown = new Actions(session).MoveToElement(_saveButton).MoveByOffset(0, _saveButton.Rect.Height).ContextClick() + .SendKeys(OpenQA.Selenium.Keys.PageDown + OpenQA.Selenium.Keys.PageDown); + Assert.IsNotNull(_scrollDown); } [ClassCleanup] public static void ClassCleanup() { + CloseSettings(); TearDown(); } @@ -499,29 +486,13 @@ public void TestInitialize() { _initialSettings = ""; } - - - OpenSettings(); - ShortWait(); } [TestCleanup] public void TestCleanup() { - try - { - WindowsElement editorWindow = session.FindElementByName("FancyZones Editor"); - if (editorWindow != null) - { - editorWindow.SendKeys(OpenQA.Selenium.Keys.Alt + OpenQA.Selenium.Keys.F4); - } - } - catch (OpenQA.Selenium.WebDriverException) - { - //editor window not found - } + ScrollUp(); - CloseSettings(); if (_initialSettings.Length > 0) { File.WriteAllText(_settingsPath, _initialSettings); diff --git a/src/tests/win-app-driver/PowerToysSession.cs b/src/tests/win-app-driver/PowerToysSession.cs index 14dc9eccf44c..7fc218347639 100644 --- a/src/tests/win-app-driver/PowerToysSession.cs +++ b/src/tests/win-app-driver/PowerToysSession.cs @@ -50,14 +50,14 @@ public static void ShortWait() Thread.Sleep(TimeSpan.FromSeconds(0.5)); } - public void OpenSettings() + public static void OpenSettings() { trayButton.Click(); session.FindElementByName("PowerToys").Click(); trayButton.Click(); } - public void CloseSettings() + public static void CloseSettings() { WindowsElement settings = session.FindElementByName("PowerToys Settings"); settings.SendKeys(Keys.Alt + Keys.F4); diff --git a/src/tests/win-app-driver/win-app-driver.csproj b/src/tests/win-app-driver/win-app-driver.csproj index a611b07d3e34..1871cdcfe773 100644 --- a/src/tests/win-app-driver/win-app-driver.csproj +++ b/src/tests/win-app-driver/win-app-driver.csproj @@ -83,7 +83,7 @@ - + From afaa5280972de6939e1cd357a289efc7bfe3c06d Mon Sep 17 00:00:00 2001 From: Serafima Zykova Date: Thu, 5 Mar 2020 19:41:09 +0300 Subject: [PATCH 16/33] added test for excluded apps input --- .../win-app-driver/FancyZonesSettingsTests.cs | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/src/tests/win-app-driver/FancyZonesSettingsTests.cs b/src/tests/win-app-driver/FancyZonesSettingsTests.cs index 1fe7f9b271af..ba26ccd67300 100644 --- a/src/tests/win-app-driver/FancyZonesSettingsTests.cs +++ b/src/tests/win-app-driver/FancyZonesSettingsTests.cs @@ -137,6 +137,13 @@ private void TestRgbInput(string name) 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); + } + [TestMethod] public void FancyZonesSettingsOpen() { @@ -444,6 +451,45 @@ public void HighlightColorTest() Assert.AreEqual("#63c99a", getPropertyValue("fancyzones_zoneHighlightColor")); } + [TestMethod] + public void ExcludeApps() + { + WindowsElement input = session.FindElementByAccessibilityId("TextField66"); + ClearInput(input); + + string inputValue; + + //valid + inputValue = "Notepad\nChrome"; + input.SendKeys(inputValue); + SaveChanges(); + ClearInput(input); + ShortWait(); + Assert.AreEqual(inputValue, getPropertyValue("fancyzones_excluded_apps")); + + //invalid + inputValue = "Notepad Chrome"; + input.SendKeys(inputValue); + SaveChanges(); + ClearInput(input); + ShortWait(); + Assert.AreEqual(inputValue, getPropertyValue("fancyzones_excluded_apps")); + + inputValue = "Notepad,Chrome"; + input.SendKeys(inputValue); + SaveChanges(); + ClearInput(input); + ShortWait(); + Assert.AreEqual(inputValue, getPropertyValue("fancyzones_excluded_apps")); + + inputValue = "Note*"; + input.SendKeys(inputValue); + SaveChanges(); + ClearInput(input); + ShortWait(); + Assert.AreEqual(inputValue, getPropertyValue("fancyzones_excluded_apps")); + } + [ClassInitialize] public static void ClassInitialize(TestContext context) { From c9c4d704c3a6be418d0686afc6da18c62a928b35 Mon Sep 17 00:00:00 2001 From: Serafima Zykova Date: Thu, 5 Mar 2020 21:23:32 +0300 Subject: [PATCH 17/33] exit without saving tests --- .../win-app-driver/FancyZonesSettingsTests.cs | 137 ++++++++++++++++-- 1 file changed, 123 insertions(+), 14 deletions(-) diff --git a/src/tests/win-app-driver/FancyZonesSettingsTests.cs b/src/tests/win-app-driver/FancyZonesSettingsTests.cs index ba26ccd67300..6788ef4fa3d3 100644 --- a/src/tests/win-app-driver/FancyZonesSettingsTests.cs +++ b/src/tests/win-app-driver/FancyZonesSettingsTests.cs @@ -20,6 +20,26 @@ public class FancyZonesSettingsTests : PowerToysSession private static Actions _scrollDown; private static Actions _scrollUp; + private static void Init() + { + OpenSettings(); + ShortWait(); + + OpenFancyZonesSettings(); + + _saveButton = session.FindElementByName("Save"); + Assert.IsNotNull(_saveButton); + + WindowsElement powerToysWindow = session.FindElementByXPath("//Window[@Name=\"PowerToys Settings\"]"); + Assert.IsNotNull(powerToysWindow); + _scrollUp = new Actions(session).MoveToElement(_saveButton).MoveByOffset(0, _saveButton.Rect.Height).ContextClick() + .SendKeys(OpenQA.Selenium.Keys.PageUp + OpenQA.Selenium.Keys.PageUp); + Assert.IsNotNull(_scrollUp); + _scrollDown = new Actions(session).MoveToElement(_saveButton).MoveByOffset(0, _saveButton.Rect.Height).ContextClick() + .SendKeys(OpenQA.Selenium.Keys.PageDown + OpenQA.Selenium.Keys.PageDown); + Assert.IsNotNull(_scrollDown); + } + private static void OpenFancyZonesSettings() { WindowsElement fzNavigationButton = session.FindElementByXPath("//Button[@Name=\"FancyZones\"]"); @@ -490,33 +510,122 @@ public void ExcludeApps() Assert.AreEqual(inputValue, getPropertyValue("fancyzones_excluded_apps")); } - [ClassInitialize] - public static void ClassInitialize(TestContext context) + [TestMethod] + public void ExitDialogSave() { - Setup(context); + JObject initialProps = _initialSettingsJson["properties"].ToObject(); + bool initialToggleValue = getPropertyValue(initialProps, "fancyzones_shiftDrag"); - OpenSettings(); - ShortWait(); + WindowsElement toggle = session.FindElementByAccessibilityId("Toggle37"); + Assert.IsNotNull(toggle); + Assert.AreEqual(initialToggleValue, toggle.Selected); + + toggle.Click(); + CloseSettings(); + WindowsElement exitDialog = session.FindElementByName("Changes not saved"); + Assert.IsNotNull(exitDialog); - OpenFancyZonesSettings(); + exitDialog.FindElementByName("Save").Click(); - _saveButton = session.FindElementByName("Save"); - Assert.IsNotNull(_saveButton); + //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.FindElementByAccessibilityId("Toggle37"); + Assert.IsNotNull(toggle); + + 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 + } + + //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 + Init(); + } + + [TestMethod] + public void ExitDialogCancel() + { + WindowsElement toggle = session.FindElementByAccessibilityId("Toggle37"); + 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); - _scrollUp = new Actions(session).MoveToElement(_saveButton).MoveByOffset(0, _saveButton.Rect.Height).ContextClick() - .SendKeys(OpenQA.Selenium.Keys.PageUp + OpenQA.Selenium.Keys.PageUp); - Assert.IsNotNull(_scrollUp); - _scrollDown = new Actions(session).MoveToElement(_saveButton).MoveByOffset(0, _saveButton.Rect.Height).ContextClick() - .SendKeys(OpenQA.Selenium.Keys.PageDown + OpenQA.Selenium.Keys.PageDown); - Assert.IsNotNull(_scrollDown); + + //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(); + } + + [ClassInitialize] + public static void ClassInitialize(TestContext context) + { + Setup(context); + 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 + } + TearDown(); } From 1000d335f04e957d542eb076cfbf282d44134050 Mon Sep 17 00:00:00 2001 From: Serafima Zykova Date: Mon, 9 Mar 2020 18:12:43 +0300 Subject: [PATCH 18/33] added test for hotkeys --- .../win-app-driver/FancyZonesSettingsTests.cs | 85 +++++++++++++++++++ 1 file changed, 85 insertions(+) diff --git a/src/tests/win-app-driver/FancyZonesSettingsTests.cs b/src/tests/win-app-driver/FancyZonesSettingsTests.cs index 6788ef4fa3d3..0cfb73662874 100644 --- a/src/tests/win-app-driver/FancyZonesSettingsTests.cs +++ b/src/tests/win-app-driver/FancyZonesSettingsTests.cs @@ -1,5 +1,7 @@ using System; +using System.Collections; using System.IO; +using System.Linq; using System.Windows.Forms; using Microsoft.VisualStudio.TestTools.UnitTesting; using Newtonsoft.Json.Linq; @@ -164,6 +166,71 @@ private void ClearInput(WindowsElement input) 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 = "", keys = ""; + if (flags[0] == 1) + { + action.KeyDown(OpenQA.Selenium.Keys.Command); + expectedText += "Win + "; + } + if (flags[1] == 1) + { + keys += OpenQA.Selenium.Keys.Control; + expectedText += "Ctrl + "; + } + if (flags[2] == 1) + { + keys += OpenQA.Selenium.Keys.Alt; + expectedText += "Alt + "; + } + if (flags[3] == 1) + { + keys += OpenQA.Selenium.Keys.Shift; + expectedText += "Shift + "; + } + + keys += key + key; + expectedText += keyString + "\r\n"; + + action.SendKeys(keys); + 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(); + ShortWait(); + + //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")); + } + [TestMethod] public void FancyZonesSettingsOpen() { @@ -601,6 +668,24 @@ public void ExitDialogCancel() SaveChanges(); } + [TestMethod] + public void ConfigureHotkey() + { + WindowsElement input = session.FindElementByAccessibilityId("TextField34"); + + for (int i = 0; i < 16; i++) + { + TestHotkey(input, i, OpenQA.Selenium.Keys.End, "End"); + } + } + + [TestMethod] + public void ConfigureLocalSymbolHotkey() + { + WindowsElement input = session.FindElementByAccessibilityId("TextField34"); + TestHotkey(input, 0, "ё", "Ё"); + } + [ClassInitialize] public static void ClassInitialize(TestContext context) { From 76b1ec561eb4322731c9a7a50faa855ff6531821 Mon Sep 17 00:00:00 2001 From: Serafima Zykova Date: Mon, 9 Mar 2020 18:13:32 +0300 Subject: [PATCH 19/33] added test case for excluded apps --- src/tests/win-app-driver/FancyZonesSettingsTests.cs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/tests/win-app-driver/FancyZonesSettingsTests.cs b/src/tests/win-app-driver/FancyZonesSettingsTests.cs index 0cfb73662874..fade868d8dcf 100644 --- a/src/tests/win-app-driver/FancyZonesSettingsTests.cs +++ b/src/tests/win-app-driver/FancyZonesSettingsTests.cs @@ -575,6 +575,13 @@ public void ExcludeApps() ClearInput(input); ShortWait(); Assert.AreEqual(inputValue, getPropertyValue("fancyzones_excluded_apps")); + + inputValue = "Кириллица"; + input.SendKeys(inputValue); + SaveChanges(); + ClearInput(input); + ShortWait(); + Assert.AreEqual(inputValue, getPropertyValue("fancyzones_excluded_apps")); } [TestMethod] From ebfa3128af09fd4b34581d2f2ca0c82246895721 Mon Sep 17 00:00:00 2001 From: Serafima Zykova Date: Tue, 10 Mar 2020 16:56:17 +0300 Subject: [PATCH 20/33] fixed elements search --- .../win-app-driver/FancyZonesSettingsTests.cs | 54 +++++++++++-------- 1 file changed, 31 insertions(+), 23 deletions(-) diff --git a/src/tests/win-app-driver/FancyZonesSettingsTests.cs b/src/tests/win-app-driver/FancyZonesSettingsTests.cs index fade868d8dcf..b854bf48b647 100644 --- a/src/tests/win-app-driver/FancyZonesSettingsTests.cs +++ b/src/tests/win-app-driver/FancyZonesSettingsTests.cs @@ -1,5 +1,6 @@ using System; using System.Collections; +using System.Collections.Generic; using System.IO; using System.Linq; using System.Windows.Forms; @@ -112,7 +113,7 @@ private void SetOpacity(WindowsElement editor, string key) private void TestRgbInput(string name) { - WindowsElement colorInput = session.FindElementByAccessibilityId(name); + WindowsElement colorInput = session.FindElementByXPath("//Edit[@Name=\"" + name + "\"]"); Assert.IsNotNull(colorInput); colorInput.SendKeys(OpenQA.Selenium.Keys.Control + OpenQA.Selenium.Keys.Backspace); @@ -258,14 +259,16 @@ public void EditorOpen() [TestMethod] public void TogglesSingleClickSaveButtonTest() { - for (int i = 37; i < 45; i++) + List toggles = session.FindElementsByXPath("//Pane[@Name=\"PowerToys Settings\"]/*[@LocalizedControlType=\"toggleswitch\"]").ToList(); + Assert.AreEqual(8, toggles.Count); + + foreach (WindowsElement toggle in toggles) { - string toggleId = "Toggle" + i.ToString(); - WindowsElement toggle = session.FindElementByAccessibilityId(toggleId); Assert.IsNotNull(toggle); toggle.Click(); SaveChanges(); + ShortWait(); } //check saved settings @@ -290,16 +293,18 @@ public void TogglesSingleClickSaveButtonTest() [TestMethod] public void TogglesDoubleClickSave() { - for (int i = 37; i < 45; i++) + List toggles = session.FindElementsByXPath("//Pane[@Name=\"PowerToys Settings\"]/*[@LocalizedControlType=\"toggleswitch\"]").ToList(); + Assert.AreEqual(8, toggles.Count); + + foreach (WindowsElement toggle in toggles) { - string toggleId = "Toggle" + i.ToString(); - WindowsElement toggle = session.FindElementByAccessibilityId(toggleId); Assert.IsNotNull(toggle); toggle.Click(); toggle.Click(); - - SaveChanges(); } + + SaveChanges(); + ShortWait(); string savedSettings = File.ReadAllText(_settingsPath); Assert.AreEqual(_initialSettings, savedSettings); @@ -408,10 +413,10 @@ public void HighlightColorSlidersTest() WindowsElement saturationAndBrightness = session.FindElementByName("Saturation and brightness"); WindowsElement hue = session.FindElementByName("Hue"); - WindowsElement hex = session.FindElementByAccessibilityId("TextField54"); - WindowsElement red = session.FindElementByAccessibilityId("TextField57"); - WindowsElement green = session.FindElementByAccessibilityId("TextField60"); - WindowsElement blue = session.FindElementByAccessibilityId("TextField63"); + WindowsElement hex = session.FindElementByXPath("//Edit[@Name=\"Hex\"]"); + WindowsElement red = session.FindElementByXPath("//Edit[@Name=\"Red\"]"); + WindowsElement green = session.FindElementByXPath("//Edit[@Name=\"Green\"]"); + WindowsElement blue = session.FindElementByXPath("//Edit[@Name=\"Blue\"]"); Assert.IsNotNull(saturationAndBrightness); Assert.IsNotNull(hue); @@ -465,9 +470,9 @@ public void HighlightRGBInputsTest() { ScrollDown(); - TestRgbInput("TextField57"); //red - TestRgbInput("TextField60"); //green - TestRgbInput("TextField63"); //blue + TestRgbInput("Red"); + TestRgbInput("Green"); + TestRgbInput("Blue"); } [TestMethod] @@ -475,9 +480,9 @@ public void HighlightHexInputTest() { ScrollDown(); - WindowsElement hexInput = session.FindElementByAccessibilityId("TextField54"); + WindowsElement hexInput = session.FindElementByXPath("//Edit[@Name=\"Hex\"]"); Assert.IsNotNull(hexInput); - + hexInput.SendKeys(OpenQA.Selenium.Keys.Control + OpenQA.Selenium.Keys.Backspace); string invalidSymbols = "qwrtyuiopsghjklzxvnm,./';][{}:`~!#@$%^&*()_-+=\"\'\\"; @@ -520,7 +525,7 @@ public void HighlightColorTest() WindowsElement saturationAndBrightness = session.FindElementByName("Saturation and brightness"); WindowsElement hue = session.FindElementByName("Hue"); - WindowsElement hex = session.FindElementByAccessibilityId("TextField54"); + WindowsElement hex = session.FindElementByXPath("//Edit[@Name=\"Hex\"]"); Assert.IsNotNull(saturationAndBrightness); Assert.IsNotNull(hue); @@ -541,7 +546,8 @@ public void HighlightColorTest() [TestMethod] public void ExcludeApps() { - WindowsElement input = session.FindElementByAccessibilityId("TextField66"); + WindowsElement input = session.FindElementByXPath("//Edit[contains(@Name, \"exclude\")]"); + Assert.IsNotNull(input); ClearInput(input); string inputValue; @@ -678,8 +684,9 @@ public void ExitDialogCancel() [TestMethod] public void ConfigureHotkey() { - WindowsElement input = session.FindElementByAccessibilityId("TextField34"); - + 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"); @@ -689,7 +696,8 @@ public void ConfigureHotkey() [TestMethod] public void ConfigureLocalSymbolHotkey() { - WindowsElement input = session.FindElementByAccessibilityId("TextField34"); + WindowsElement input = session.FindElementByXPath("//Edit[contains(@Name, \"hotkey\")]"); + Assert.IsNotNull(input); TestHotkey(input, 0, "ё", "Ё"); } From cc3293e481aaf3a451788f2a6eee3b2424b5d322 Mon Sep 17 00:00:00 2001 From: Serafima Zykova Date: Wed, 11 Mar 2020 16:58:43 +0300 Subject: [PATCH 21/33] refactoring --- .../win-app-driver/FancyZonesSettingsTests.cs | 67 ++++++++++--------- 1 file changed, 34 insertions(+), 33 deletions(-) diff --git a/src/tests/win-app-driver/FancyZonesSettingsTests.cs b/src/tests/win-app-driver/FancyZonesSettingsTests.cs index b854bf48b647..e14a41c5e077 100644 --- a/src/tests/win-app-driver/FancyZonesSettingsTests.cs +++ b/src/tests/win-app-driver/FancyZonesSettingsTests.cs @@ -173,7 +173,7 @@ private void TestHotkey(WindowsElement input, int modifierKeysState, string key, int[] flags = b.Cast().Select(bit => bit ? 1 : 0).ToArray(); Actions action = new Actions(session).MoveToElement(input).Click(); - string expectedText = "", keys = ""; + string expectedText = ""; if (flags[0] == 1) { action.KeyDown(OpenQA.Selenium.Keys.Command); @@ -181,24 +181,23 @@ private void TestHotkey(WindowsElement input, int modifierKeysState, string key, } if (flags[1] == 1) { - keys += OpenQA.Selenium.Keys.Control; + action.KeyDown(OpenQA.Selenium.Keys.Control); expectedText += "Ctrl + "; } if (flags[2] == 1) { - keys += OpenQA.Selenium.Keys.Alt; + action.KeyDown(OpenQA.Selenium.Keys.Alt); expectedText += "Alt + "; } if (flags[3] == 1) { - keys += OpenQA.Selenium.Keys.Shift; + action.KeyDown(OpenQA.Selenium.Keys.Shift); expectedText += "Shift + "; } - keys += key + key; expectedText += keyString + "\r\n"; - action.SendKeys(keys); + action.SendKeys(key + key); action.MoveByOffset(0, (input.Rect.Height / 2) + 10).ContextClick(); if (flags[0] == 1) { @@ -217,7 +216,7 @@ private void TestHotkey(WindowsElement input, int modifierKeysState, string key, action.KeyUp(OpenQA.Selenium.Keys.Shift); } action.Perform(); - + SaveChanges(); ShortWait(); @@ -406,6 +405,8 @@ public void HighlightOpacityClearValueButton() Assert.AreEqual("\r\n", editor.Text); } + //in 0.15.2 sliders cannot be found by inspect.exe + /* [TestMethod] public void HighlightColorSlidersTest() { @@ -464,6 +465,32 @@ public void HighlightColorSlidersTest() ShortWait(); Assert.AreEqual("#ff0000", getPropertyValue("fancyzones_zoneHighlightColor")); } + + [TestMethod] + public void HighlightColorTest() + { + ScrollDown(); + + 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(); + ShortWait(); + Assert.AreEqual("#63c99a", getPropertyValue("fancyzones_zoneHighlightColor")); + } + */ [TestMethod] public void HighlightRGBInputsTest() @@ -518,31 +545,6 @@ public void HighlightHexInputTest() Assert.AreEqual("112233\r\n", hexInput.Text); } - [TestMethod] - public void HighlightColorTest() - { - ScrollDown(); - - 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(); - ShortWait(); - Assert.AreEqual("#63c99a", getPropertyValue("fancyzones_zoneHighlightColor")); - } - [TestMethod] public void ExcludeApps() { @@ -607,7 +609,6 @@ public void ExitDialogSave() exitDialog.FindElementByName("Save").Click(); - //check if window still opened WindowsElement powerToysWindow = session.FindElementByXPath("//Window[@Name=\"PowerToys Settings\"]"); Assert.IsNotNull(powerToysWindow); From c1751e51412a9cd36f5a8b07d9dcc6accd7bf4ec Mon Sep 17 00:00:00 2001 From: Serafima Zykova Date: Wed, 11 Mar 2020 18:29:22 +0300 Subject: [PATCH 22/33] updated toggles tests --- .../win-app-driver/FancyZonesSettingsTests.cs | 67 ++++++++++++------- 1 file changed, 41 insertions(+), 26 deletions(-) diff --git a/src/tests/win-app-driver/FancyZonesSettingsTests.cs b/src/tests/win-app-driver/FancyZonesSettingsTests.cs index e14a41c5e077..e1347f89a17a 100644 --- a/src/tests/win-app-driver/FancyZonesSettingsTests.cs +++ b/src/tests/win-app-driver/FancyZonesSettingsTests.cs @@ -261,9 +261,14 @@ public void TogglesSingleClickSaveButtonTest() List toggles = session.FindElementsByXPath("//Pane[@Name=\"PowerToys Settings\"]/*[@LocalizedControlType=\"toggleswitch\"]").ToList(); Assert.AreEqual(8, 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(); @@ -272,16 +277,14 @@ public void TogglesSingleClickSaveButtonTest() //check saved settings JObject savedProps = getProperties(); - JObject initialProps = _initialSettingsJson["properties"].ToObject(); - - Assert.AreNotEqual(getPropertyValue(initialProps, "fancyzones_shiftDrag"), getPropertyValue(savedProps, "fancyzones_shiftDrag")); - Assert.AreNotEqual(getPropertyValue(initialProps, "fancyzones_overrideSnapHotkeys"), getPropertyValue(savedProps, "fancyzones_overrideSnapHotkeys")); - Assert.AreNotEqual(getPropertyValue(initialProps, "fancyzones_zoneSetChange_flashZones"), getPropertyValue(savedProps, "fancyzones_zoneSetChange_flashZones")); - Assert.AreNotEqual(getPropertyValue(initialProps, "fancyzones_displayChange_moveWindows"), getPropertyValue(savedProps, "fancyzones_displayChange_moveWindows")); - Assert.AreNotEqual(getPropertyValue(initialProps, "fancyzones_zoneSetChange_moveWindows"), getPropertyValue(savedProps, "fancyzones_zoneSetChange_moveWindows")); - Assert.AreNotEqual(getPropertyValue(initialProps, "fancyzones_virtualDesktopChange_moveWindows"), getPropertyValue(savedProps, "fancyzones_virtualDesktopChange_moveWindows")); - Assert.AreNotEqual(getPropertyValue(initialProps, "fancyzones_appLastZone_moveWindows"), getPropertyValue(savedProps, "fancyzones_appLastZone_moveWindows")); - Assert.AreNotEqual(getPropertyValue(initialProps, "use_cursorpos_editor_startupscreen"), getPropertyValue(savedProps, "use_cursorpos_editor_startupscreen")); + Assert.AreNotEqual(toggleValues[0], getPropertyValue(savedProps, "fancyzones_shiftDrag")); + Assert.AreNotEqual(toggleValues[1], getPropertyValue(savedProps, "fancyzones_overrideSnapHotkeys")); + Assert.AreNotEqual(toggleValues[2], getPropertyValue(savedProps, "fancyzones_zoneSetChange_flashZones")); + Assert.AreNotEqual(toggleValues[3], getPropertyValue(savedProps, "fancyzones_displayChange_moveWindows")); + Assert.AreNotEqual(toggleValues[4], getPropertyValue(savedProps, "fancyzones_zoneSetChange_moveWindows")); + Assert.AreNotEqual(toggleValues[5], getPropertyValue(savedProps, "fancyzones_virtualDesktopChange_moveWindows")); + Assert.AreNotEqual(toggleValues[6], getPropertyValue(savedProps, "fancyzones_appLastZone_moveWindows")); + Assert.AreNotEqual(toggleValues[7], getPropertyValue(savedProps, "use_cursorpos_editor_startupscreen")); } /* @@ -295,9 +298,14 @@ public void TogglesDoubleClickSave() List toggles = session.FindElementsByXPath("//Pane[@Name=\"PowerToys Settings\"]/*[@LocalizedControlType=\"toggleswitch\"]").ToList(); Assert.AreEqual(8, 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(); } @@ -305,8 +313,15 @@ public void TogglesDoubleClickSave() SaveChanges(); ShortWait(); - string savedSettings = File.ReadAllText(_settingsPath); - Assert.AreEqual(_initialSettings, savedSettings); + JObject savedProps = getProperties(); + Assert.AreEqual(toggleValues[0], getPropertyValue(savedProps, "fancyzones_shiftDrag")); + Assert.AreEqual(toggleValues[1], getPropertyValue(savedProps, "fancyzones_overrideSnapHotkeys")); + Assert.AreEqual(toggleValues[2], getPropertyValue(savedProps, "fancyzones_zoneSetChange_flashZones")); + Assert.AreEqual(toggleValues[3], getPropertyValue(savedProps, "fancyzones_displayChange_moveWindows")); + Assert.AreEqual(toggleValues[4], getPropertyValue(savedProps, "fancyzones_zoneSetChange_moveWindows")); + Assert.AreEqual(toggleValues[5], getPropertyValue(savedProps, "fancyzones_virtualDesktopChange_moveWindows")); + Assert.AreEqual(toggleValues[6], getPropertyValue(savedProps, "fancyzones_appLastZone_moveWindows")); + Assert.AreEqual(toggleValues[7], getPropertyValue(savedProps, "use_cursorpos_editor_startupscreen")); } [TestMethod] @@ -595,13 +610,11 @@ public void ExcludeApps() [TestMethod] public void ExitDialogSave() { - JObject initialProps = _initialSettingsJson["properties"].ToObject(); - bool initialToggleValue = getPropertyValue(initialProps, "fancyzones_shiftDrag"); - - WindowsElement toggle = session.FindElementByAccessibilityId("Toggle37"); + WindowsElement toggle = session.FindElementByXPath("//Pane[@Name=\"PowerToys Settings\"]/*[@LocalizedControlType=\"toggleswitch\"]"); Assert.IsNotNull(toggle); - Assert.AreEqual(initialToggleValue, toggle.Selected); - + + bool initialToggleValue = toggle.GetAttribute("Toggle.ToggleState") == "1"; + toggle.Click(); CloseSettings(); WindowsElement exitDialog = session.FindElementByName("Changes not saved"); @@ -625,11 +638,14 @@ public void ExitDialogSave() [TestMethod] public void ExitDialogExit() { - WindowsElement toggle = session.FindElementByAccessibilityId("Toggle37"); + 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); @@ -644,21 +660,20 @@ public void ExitDialogExit() catch(OpenQA.Selenium.WebDriverException) { //window is no longer available, which is expected - } - - //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 Init(); + + //check settings change + JObject savedProps = getProperties(); + Assert.AreEqual(initialToggleValue, getPropertyValue(savedProps, "fancyzones_shiftDrag")); } [TestMethod] public void ExitDialogCancel() { - WindowsElement toggle = session.FindElementByAccessibilityId("Toggle37"); + WindowsElement toggle = session.FindElementByXPath("//Pane[@Name=\"PowerToys Settings\"]/*[@LocalizedControlType=\"toggleswitch\"]"); Assert.IsNotNull(toggle); toggle.Click(); From 6b432a965a41fd7492227a6fad40937d40594ebb Mon Sep 17 00:00:00 2001 From: Serafima Zykova Date: Wed, 11 Mar 2020 18:50:00 +0300 Subject: [PATCH 23/33] README update --- src/tests/win-app-driver/README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/tests/win-app-driver/README.md b/src/tests/win-app-driver/README.md index c0425a15c6f9..3e5c0519313b 100644 --- a/src/tests/win-app-driver/README.md +++ b/src/tests/win-app-driver/README.md @@ -3,13 +3,13 @@ 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 Windows Application Driver in the test machine: https://github.com/Microsoft/WinAppDriver/releases - - Install the ".Net desktop development" components in Visual Studio 2017. It should have support for "C#" and ".Net Framework 4.6.1". + - Install the latest stable version of Windows Application Driver in the test machine: 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". ## Running the tests ### Preparing the test machine - - Start `powertoys.exe`. + - Start `PowerToys.exe`. - Set Windows to "Developer Mode", by selecting `Developer mode` in `Settings > For developers > Use developer features` in Windows 10. - Run the "Windows Application Driver" in Administrator mode in the test machine. From b124ce03b46e451e07d637380b7c9e8e1d51d3ba Mon Sep 17 00:00:00 2001 From: Serafima Date: Fri, 13 Mar 2020 12:04:11 +0300 Subject: [PATCH 24/33] fix settings reading --- .../win-app-driver/FancyZonesSettingsTests.cs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/tests/win-app-driver/FancyZonesSettingsTests.cs b/src/tests/win-app-driver/FancyZonesSettingsTests.cs index e1347f89a17a..0fad8657100f 100644 --- a/src/tests/win-app-driver/FancyZonesSettingsTests.cs +++ b/src/tests/win-app-driver/FancyZonesSettingsTests.cs @@ -14,9 +14,9 @@ namespace PowerToysTests { [TestClass] public class FancyZonesSettingsTests : PowerToysSession - { - private string _settingsPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Microsoft/PowerToys/FancyZones/settings.json"); - private string _initialSettings; + { + private static string _settingsPath = ""; + private string _initialSettings = ""; private JObject _initialSettingsJson; private static WindowsElement _saveButton; @@ -721,6 +721,14 @@ public void ConfigureLocalSymbolHotkey() public static void ClassInitialize(TestContext context) { Setup(context); + + string settingsFolderPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Microsoft/PowerToys/FancyZones"); + if (!Directory.Exists(settingsFolderPath)) + { + Directory.CreateDirectory(settingsFolderPath); + } + _settingsPath = settingsFolderPath + "/settings.json"; + Init(); } From d4978e3d65b56da8814081e46df3235d74b9bf4a Mon Sep 17 00:00:00 2001 From: Serafima Date: Fri, 13 Mar 2020 12:24:46 +0300 Subject: [PATCH 25/33] readme update --- src/tests/win-app-driver/README.md | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/tests/win-app-driver/README.md b/src/tests/win-app-driver/README.md index 3e5c0519313b..af05d440e370 100644 --- a/src/tests/win-app-driver/README.md +++ b/src/tests/win-app-driver/README.md @@ -5,13 +5,16 @@ The PowerToys tests are implemented using Appium and use the [Windows Applicatio ## Prerequisites - Install the latest stable version of Windows Application Driver in the test machine: 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 v0.15.2](https://github.com/microsoft/PowerToys/releases/download/v0.15.2/PowerToysSetup-0.15.2-x64.msix) + - Set Windows to "Developer Mode", by selecting `Developer mode` in `Settings > For developers > Use developer features` in Windows 10. -## Running the tests +If you have `PowerToys v0.15.2 (MSIX)` installed, it can be launched automatically. Otherwise you should start `PowerToys` before running tests. ### Preparing the test machine - - Start `PowerToys.exe`. - - Set Windows to "Developer Mode", by selecting `Developer mode` in `Settings > For developers > Use developer features` in Windows 10. - - Run the "Windows Application Driver" in Administrator mode in the test machine. + - Start `PowerToys` if it is necessary. + - Run the "Windows Application Driver" in Administrator mode in the test machine. By default you can find it in `C:\Program Files (x86)\Windows Application Driver` + + - Notice that notifications or other application windows that are shown above PowerToys settings window or tray can disrupt testing process. When testing on a remote machine, 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): From 3e3b4f0d130a53714c6ceb27f608052fb13660d9 Mon Sep 17 00:00:00 2001 From: Serafima Date: Fri, 13 Mar 2020 12:36:09 +0300 Subject: [PATCH 26/33] updated link in readme --- src/tests/win-app-driver/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tests/win-app-driver/README.md b/src/tests/win-app-driver/README.md index af05d440e370..1f7dcef9eec1 100644 --- a/src/tests/win-app-driver/README.md +++ b/src/tests/win-app-driver/README.md @@ -3,7 +3,7 @@ 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: https://github.com/microsoft/WinAppDriver/releases/tag/v1.1 + - 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 v0.15.2](https://github.com/microsoft/PowerToys/releases/download/v0.15.2/PowerToysSetup-0.15.2-x64.msix) - Set Windows to "Developer Mode", by selecting `Developer mode` in `Settings > For developers > Use developer features` in Windows 10. From 38bbcc397deea0bd5029448caa6b441f421d76f2 Mon Sep 17 00:00:00 2001 From: Serafima Zykova Date: Fri, 13 Mar 2020 18:27:40 +0300 Subject: [PATCH 27/33] added test plan for editor --- .../FancyZonesSettingsTests.cs | 0 .../win-app-driver/FancyZonesTests/README.md | 39 +++++++++++++++++++ .../win-app-driver/win-app-driver.csproj | 3 +- 3 files changed, 41 insertions(+), 1 deletion(-) rename src/tests/win-app-driver/{ => FancyZonesTests}/FancyZonesSettingsTests.cs (100%) create mode 100644 src/tests/win-app-driver/FancyZonesTests/README.md diff --git a/src/tests/win-app-driver/FancyZonesSettingsTests.cs b/src/tests/win-app-driver/FancyZonesTests/FancyZonesSettingsTests.cs similarity index 100% rename from src/tests/win-app-driver/FancyZonesSettingsTests.cs rename to src/tests/win-app-driver/FancyZonesTests/FancyZonesSettingsTests.cs diff --git a/src/tests/win-app-driver/FancyZonesTests/README.md b/src/tests/win-app-driver/FancyZonesTests/README.md new file mode 100644 index 000000000000..7a31ed906098 --- /dev/null +++ b/src/tests/win-app-driver/FancyZonesTests/README.md @@ -0,0 +1,39 @@ +# FancyZones Test Plan + +## Settings + - [x] Test if settings are saved in file properly + +## Editor + - [] Open editor by clicking button from settings + - [] without settings file + - [] with valid settings file + - [] with invalid settings file + - [] Open editor by hotkey with opened settings window + - [] without settings file + - [] with valid settings file + - [] with invalid settings file + - [] Open editor by hotkey with closed settings window + - [] without settings file + - [] with valid settings file + - [] with invalid settings 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/win-app-driver.csproj b/src/tests/win-app-driver/win-app-driver.csproj index 1871cdcfe773..adee49eaf145 100644 --- a/src/tests/win-app-driver/win-app-driver.csproj +++ b/src/tests/win-app-driver/win-app-driver.csproj @@ -83,7 +83,7 @@ - + @@ -95,6 +95,7 @@ + From 4f73ba1cf340b45fa8e191dc76f56366e5a2505e Mon Sep 17 00:00:00 2001 From: Serafima Zykova Date: Mon, 16 Mar 2020 15:33:21 +0300 Subject: [PATCH 28/33] resolved conflicts after rebase --- PowerToys.sln | 56 +++++++++++++++++++++++++++++++++++---------------- 1 file changed, 39 insertions(+), 17 deletions(-) diff --git a/PowerToys.sln b/PowerToys.sln index a101942620e1..40cc7dc6ba27 100644 --- a/PowerToys.sln +++ b/PowerToys.sln @@ -1,4 +1,4 @@ - + Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 16 VisualStudioVersion = 16.0.28803.452 @@ -271,18 +271,6 @@ Global {0485F45C-EA7A-4BB5-804B-3E8D14699387}.Release|x64.ActiveCfg = Release|x64 {0485F45C-EA7A-4BB5-804B-3E8D14699387}.Release|x64.Build.0 = Release|x64 {0B593A6C-4143-4337-860E-DB5710FB87DB}.Debug|Any CPU.ActiveCfg = Debug|Win32 - {2BE46397-4DFA-414C-9BD4-41E4BBF8CB34}.Debug|x64.ActiveCfg = Debug|x64 - {2BE46397-4DFA-414C-9BD4-41E4BBF8CB34}.Debug|x64.Build.0 = Debug|x64 - {2BE46397-4DFA-414C-9BD4-41E4BBF8CB34}.Release|x64.ActiveCfg = Release|x64 - {2BE46397-4DFA-414C-9BD4-41E4BBF8CB34}.Release|x64.Build.0 = Release|x64 - {0B43679E-EDFA-4DA0-AD30-F4628B308B1B}.Debug|x64.ActiveCfg = Debug|x64 - {0B43679E-EDFA-4DA0-AD30-F4628B308B1B}.Debug|x64.Build.0 = Debug|x64 - {0B43679E-EDFA-4DA0-AD30-F4628B308B1B}.Release|x64.ActiveCfg = Release|x64 - {0B43679E-EDFA-4DA0-AD30-F4628B308B1B}.Release|x64.Build.0 = Release|x64 - {E0CC7526-D85E-43AC-844F-D5DF0D2F5AB8}.Debug|x64.ActiveCfg = Debug|x64 - {E0CC7526-D85E-43AC-844F-D5DF0D2F5AB8}.Debug|x64.Build.0 = Debug|x64 - {E0CC7526-D85E-43AC-844F-D5DF0D2F5AB8}.Release|x64.ActiveCfg = Release|x64 - {E0CC7526-D85E-43AC-844F-D5DF0D2F5AB8}.Release|x64.Build.0 = Release|x64 {0B593A6C-4143-4337-860E-DB5710FB87DB}.Debug|x64.ActiveCfg = Debug|x64 {0B593A6C-4143-4337-860E-DB5710FB87DB}.Debug|x64.Build.0 = Debug|x64 {0B593A6C-4143-4337-860E-DB5710FB87DB}.Release|Any CPU.ActiveCfg = Release|Win32 @@ -306,6 +294,24 @@ Global {51D3BD1F-07A8-48EB-B2A0-0A249CD4E1A6}.Release|Any CPU.ActiveCfg = Release|x64 {51D3BD1F-07A8-48EB-B2A0-0A249CD4E1A6}.Release|x64.ActiveCfg = Release|x64 {51D3BD1F-07A8-48EB-B2A0-0A249CD4E1A6}.Release|x64.Build.0 = Release|x64 + {2BE46397-4DFA-414C-9BD4-41E4BBF8CB34}.Debug|Any CPU.ActiveCfg = Debug|x64 + {2BE46397-4DFA-414C-9BD4-41E4BBF8CB34}.Debug|x64.ActiveCfg = Debug|x64 + {2BE46397-4DFA-414C-9BD4-41E4BBF8CB34}.Debug|x64.Build.0 = Debug|x64 + {2BE46397-4DFA-414C-9BD4-41E4BBF8CB34}.Release|Any CPU.ActiveCfg = Release|x64 + {2BE46397-4DFA-414C-9BD4-41E4BBF8CB34}.Release|x64.ActiveCfg = Release|x64 + {2BE46397-4DFA-414C-9BD4-41E4BBF8CB34}.Release|x64.Build.0 = Release|x64 + {0B43679E-EDFA-4DA0-AD30-F4628B308B1B}.Debug|Any CPU.ActiveCfg = Debug|Win32 + {0B43679E-EDFA-4DA0-AD30-F4628B308B1B}.Debug|x64.ActiveCfg = Debug|x64 + {0B43679E-EDFA-4DA0-AD30-F4628B308B1B}.Debug|x64.Build.0 = Debug|x64 + {0B43679E-EDFA-4DA0-AD30-F4628B308B1B}.Release|Any CPU.ActiveCfg = Release|Win32 + {0B43679E-EDFA-4DA0-AD30-F4628B308B1B}.Release|x64.ActiveCfg = Release|x64 + {0B43679E-EDFA-4DA0-AD30-F4628B308B1B}.Release|x64.Build.0 = Release|x64 + {E0CC7526-D85E-43AC-844F-D5DF0D2F5AB8}.Debug|Any CPU.ActiveCfg = Debug|x64 + {E0CC7526-D85E-43AC-844F-D5DF0D2F5AB8}.Debug|x64.ActiveCfg = Debug|x64 + {E0CC7526-D85E-43AC-844F-D5DF0D2F5AB8}.Debug|x64.Build.0 = Debug|x64 + {E0CC7526-D85E-43AC-844F-D5DF0D2F5AB8}.Release|Any CPU.ActiveCfg = Release|x64 + {E0CC7526-D85E-43AC-844F-D5DF0D2F5AB8}.Release|x64.ActiveCfg = Release|x64 + {E0CC7526-D85E-43AC-844F-D5DF0D2F5AB8}.Release|x64.Build.0 = Release|x64 {D29DDD63-E2CF-4657-9FD5-2AEDE4257E5D}.Debug|Any CPU.ActiveCfg = Debug|Win32 {D29DDD63-E2CF-4657-9FD5-2AEDE4257E5D}.Debug|x64.ActiveCfg = Debug|x64 {D29DDD63-E2CF-4657-9FD5-2AEDE4257E5D}.Debug|x64.Build.0 = Debug|x64 @@ -326,36 +332,52 @@ Global {880ED251-9E16-4713-9A70-D35FE0C01669}.Release|Any CPU.Build.0 = Release|Any CPU {880ED251-9E16-4713-9A70-D35FE0C01669}.Release|x64.ActiveCfg = Release|Any CPU {880ED251-9E16-4713-9A70-D35FE0C01669}.Release|x64.Build.0 = Release|Any CPU + {AF2349B8-E5B6-4004-9502-687C1C7730B1}.Debug|Any CPU.ActiveCfg = Debug|x64 {AF2349B8-E5B6-4004-9502-687C1C7730B1}.Debug|x64.ActiveCfg = Debug|x64 {AF2349B8-E5B6-4004-9502-687C1C7730B1}.Debug|x64.Build.0 = Debug|x64 + {AF2349B8-E5B6-4004-9502-687C1C7730B1}.Release|Any CPU.ActiveCfg = Release|x64 {AF2349B8-E5B6-4004-9502-687C1C7730B1}.Release|x64.ActiveCfg = Release|x64 {AF2349B8-E5B6-4004-9502-687C1C7730B1}.Release|x64.Build.0 = Release|x64 + {6A71162E-FC4C-4A2C-B90F-3CF94F59A9BB}.Debug|Any CPU.ActiveCfg = Debug|x64 {6A71162E-FC4C-4A2C-B90F-3CF94F59A9BB}.Debug|x64.ActiveCfg = Debug|x64 {6A71162E-FC4C-4A2C-B90F-3CF94F59A9BB}.Debug|x64.Build.0 = Debug|x64 + {6A71162E-FC4C-4A2C-B90F-3CF94F59A9BB}.Release|Any CPU.ActiveCfg = Release|x64 {6A71162E-FC4C-4A2C-B90F-3CF94F59A9BB}.Release|x64.ActiveCfg = Release|x64 {6A71162E-FC4C-4A2C-B90F-3CF94F59A9BB}.Release|x64.Build.0 = Release|x64 + {A2B51B8B-8F90-424E-BC97-F9AB7D76CA1A}.Debug|Any CPU.ActiveCfg = Debug|x64 {A2B51B8B-8F90-424E-BC97-F9AB7D76CA1A}.Debug|x64.ActiveCfg = Debug|x64 {A2B51B8B-8F90-424E-BC97-F9AB7D76CA1A}.Debug|x64.Build.0 = Debug|x64 + {A2B51B8B-8F90-424E-BC97-F9AB7D76CA1A}.Release|Any CPU.ActiveCfg = Release|x64 {A2B51B8B-8F90-424E-BC97-F9AB7D76CA1A}.Release|x64.ActiveCfg = Release|x64 {A2B51B8B-8F90-424E-BC97-F9AB7D76CA1A}.Release|x64.Build.0 = Release|x64 + {DA425894-6E13-404F-8DCB-78584EC0557A}.Debug|Any CPU.ActiveCfg = Debug|x64 {DA425894-6E13-404F-8DCB-78584EC0557A}.Debug|x64.ActiveCfg = Debug|x64 {DA425894-6E13-404F-8DCB-78584EC0557A}.Debug|x64.Build.0 = Debug|x64 + {DA425894-6E13-404F-8DCB-78584EC0557A}.Release|Any CPU.ActiveCfg = Release|x64 {DA425894-6E13-404F-8DCB-78584EC0557A}.Release|x64.ActiveCfg = Release|x64 {DA425894-6E13-404F-8DCB-78584EC0557A}.Release|x64.Build.0 = Release|x64 + {060D75DA-2D1C-48E6-A4A1-6F0718B64661}.Debug|Any CPU.ActiveCfg = Debug|x64 {060D75DA-2D1C-48E6-A4A1-6F0718B64661}.Debug|x64.ActiveCfg = Debug|x64 {060D75DA-2D1C-48E6-A4A1-6F0718B64661}.Debug|x64.Build.0 = Debug|x64 + {060D75DA-2D1C-48E6-A4A1-6F0718B64661}.Release|Any CPU.ActiveCfg = Release|x64 {060D75DA-2D1C-48E6-A4A1-6F0718B64661}.Release|x64.ActiveCfg = Release|x64 {060D75DA-2D1C-48E6-A4A1-6F0718B64661}.Release|x64.Build.0 = Release|x64 + {748417CA-F17E-487F-9411-CAFB6D3F4877}.Debug|Any CPU.ActiveCfg = Debug|x64 {748417CA-F17E-487F-9411-CAFB6D3F4877}.Debug|x64.ActiveCfg = Debug|x64 {748417CA-F17E-487F-9411-CAFB6D3F4877}.Debug|x64.Build.0 = Debug|x64 + {748417CA-F17E-487F-9411-CAFB6D3F4877}.Release|Any CPU.ActiveCfg = Release|x64 {748417CA-F17E-487F-9411-CAFB6D3F4877}.Release|x64.ActiveCfg = Release|x64 {748417CA-F17E-487F-9411-CAFB6D3F4877}.Release|x64.Build.0 = Release|x64 + {217DF501-135C-4E38-BFC8-99D4821032EA}.Debug|Any CPU.ActiveCfg = Debug|x64 {217DF501-135C-4E38-BFC8-99D4821032EA}.Debug|x64.ActiveCfg = Debug|x64 {217DF501-135C-4E38-BFC8-99D4821032EA}.Debug|x64.Build.0 = Debug|x64 + {217DF501-135C-4E38-BFC8-99D4821032EA}.Release|Any CPU.ActiveCfg = Release|x64 {217DF501-135C-4E38-BFC8-99D4821032EA}.Release|x64.ActiveCfg = Release|x64 {217DF501-135C-4E38-BFC8-99D4821032EA}.Release|x64.Build.0 = Release|x64 + {47310AB4-9034-4BD1-8D8B-E88AD21A171B}.Debug|Any CPU.ActiveCfg = Debug|Win32 {47310AB4-9034-4BD1-8D8B-E88AD21A171B}.Debug|x64.ActiveCfg = Debug|x64 {47310AB4-9034-4BD1-8D8B-E88AD21A171B}.Debug|x64.Build.0 = Debug|x64 + {47310AB4-9034-4BD1-8D8B-E88AD21A171B}.Release|Any CPU.ActiveCfg = Release|Win32 {47310AB4-9034-4BD1-8D8B-E88AD21A171B}.Release|x64.ActiveCfg = Release|x64 {47310AB4-9034-4BD1-8D8B-E88AD21A171B}.Release|x64.Build.0 = Release|x64 EndGlobalSection @@ -381,15 +403,15 @@ Global {2151F984-E006-4A9F-92EF-C6DDE3DC8413} = {89E20BCE-EB9C-46C8-8B50-E01A82E6FDC3} {64A80062-4D8B-4229-8A38-DFA1D7497749} = {BEEAB7F2-FFF6-45AB-9CDB-B04CC0734B88} {0485F45C-EA7A-4BB5-804B-3E8D14699387} = {89E20BCE-EB9C-46C8-8B50-E01A82E6FDC3} - {6C7F47CC-2151-44A3-A546-41C70025132C} = {4574FDD0-F61D-4376-98BF-E5A1262C11EC} - {2BE46397-4DFA-414C-9BD4-41E4BBF8CB34} = {6C7F47CC-2151-44A3-A546-41C70025132C} - {0B43679E-EDFA-4DA0-AD30-F4628B308B1B} = {6C7F47CC-2151-44A3-A546-41C70025132C} - {E0CC7526-D85E-43AC-844F-D5DF0D2F5AB8} = {6C7F47CC-2151-44A3-A546-41C70025132C} {0B593A6C-4143-4337-860E-DB5710FB87DB} = {1AFB6476-670D-4E80-A464-657E01DFF482} {031AC72E-FA28-4AB7-B690-6F7B9C28AA73} = {1AFB6476-670D-4E80-A464-657E01DFF482} {8DC78AF7-DC3E-4C57-A8FB-7E347DE74A03} = {4574FDD0-F61D-4376-98BF-E5A1262C11EC} {B9BDF8BE-FED7-49B5-A7AE-DD4D1CA2D9EB} = {8DC78AF7-DC3E-4C57-A8FB-7E347DE74A03} {51D3BD1F-07A8-48EB-B2A0-0A249CD4E1A6} = {8DC78AF7-DC3E-4C57-A8FB-7E347DE74A03} + {6C7F47CC-2151-44A3-A546-41C70025132C} = {4574FDD0-F61D-4376-98BF-E5A1262C11EC} + {2BE46397-4DFA-414C-9BD4-41E4BBF8CB34} = {6C7F47CC-2151-44A3-A546-41C70025132C} + {0B43679E-EDFA-4DA0-AD30-F4628B308B1B} = {6C7F47CC-2151-44A3-A546-41C70025132C} + {E0CC7526-D85E-43AC-844F-D5DF0D2F5AB8} = {6C7F47CC-2151-44A3-A546-41C70025132C} {17DA04DF-E393-4397-9CF0-84DABE11032E} = {1AFB6476-670D-4E80-A464-657E01DFF482} {880ED251-9E16-4713-9A70-D35FE0C01669} = {E775CC2C-24CB-48D6-9C3A-BE4CCE0DB17A} {2F305555-C296-497E-AC20-5FA1B237996A} = {4574FDD0-F61D-4376-98BF-E5A1262C11EC} From 9cf991c0fcd4fe108c1582ca245d6da299dda55a Mon Sep 17 00:00:00 2001 From: Serafima Zykova Date: Mon, 16 Mar 2020 15:33:55 +0300 Subject: [PATCH 29/33] fixed warnings --- .../win-app-driver/PowerToysTrayTests.cs | 32 ++++++++++--------- .../win-app-driver/TestShortcutHelper.cs | 17 +++++----- 2 files changed, 25 insertions(+), 24 deletions(-) diff --git a/src/tests/win-app-driver/PowerToysTrayTests.cs b/src/tests/win-app-driver/PowerToysTrayTests.cs index 542de481ae94..f4588935fc20 100644 --- a/src/tests/win-app-driver/PowerToysTrayTests.cs +++ b/src/tests/win-app-driver/PowerToysTrayTests.cs @@ -1,7 +1,6 @@ -using System; -using Microsoft.VisualStudio.TestTools.UnitTesting; +using Microsoft.VisualStudio.TestTools.UnitTesting; using OpenQA.Selenium.Appium.Windows; -using System.Threading; +using OpenQA.Selenium.Interactions; namespace PowerToysTests { @@ -15,7 +14,7 @@ public class PowerToysTrayTests : PowerToysSession public void SettingsOpen() { OpenSettings(); - Thread.Sleep(TimeSpan.FromSeconds(0.5)); + ShortWait(); //check settings window opened WindowsElement settingsWindow = session.FindElementByName("PowerToys Settings"); @@ -35,13 +34,13 @@ public void SettingsOpenWithContextMenu() WindowsElement pt = session.FindElementByName("PowerToys"); Assert.IsNotNull(pt); - session.Mouse.ContextClick(pt.Coordinates); - Thread.Sleep(TimeSpan.FromSeconds(0.5)); + new Actions(session).MoveToElement(pt).ContextClick().Perform(); + ShortWait(); //open settings - session.FindElementByXPath("//MenuItem[@AutomationId=\"40002\"]").Click(); - Thread.Sleep(TimeSpan.FromSeconds(0.5)); - + session.FindElementByXPath("//MenuItem[@Name=\"Settings\"]").Click(); + ShortWait(); + //check settings window opened WindowsElement settingsWindow = session.FindElementByName("PowerToys Settings"); Assert.IsNotNull(settingsWindow); @@ -59,17 +58,18 @@ public void PowerToysExit() WindowsElement pt = session.FindElementByName("PowerToys"); Assert.IsNotNull(pt); - session.Mouse.ContextClick(pt.Coordinates); - Thread.Sleep(TimeSpan.FromSeconds(0.5)); + new Actions(session).MoveToElement(pt).ContextClick().Perform(); + ShortWait(); //exit - session.FindElementByXPath("//MenuItem[@AutomationId=\"40001\"]").Click(); - Thread.Sleep(TimeSpan.FromSeconds(0.5)); + session.FindElementByXPath("//MenuItem[@Name=\"Exit\"]").Click(); + ShortWait(); //check PowerToys exited + pt = null; try { - Assert.IsNull(session.FindElementByName("PowerToys")); + pt = session.FindElementByName("PowerToys"); } catch (OpenQA.Selenium.WebDriverException) { @@ -77,7 +77,9 @@ public void PowerToysExit() } LaunchPowerToys(); - Thread.Sleep(TimeSpan.FromSeconds(0.5)); + ShortWait(); + + Assert.IsNull(pt); } [ClassInitialize] diff --git a/src/tests/win-app-driver/TestShortcutHelper.cs b/src/tests/win-app-driver/TestShortcutHelper.cs index 5a198f361c8b..286031116cd1 100644 --- a/src/tests/win-app-driver/TestShortcutHelper.cs +++ b/src/tests/win-app-driver/TestShortcutHelper.cs @@ -1,10 +1,9 @@ using System; +using System.Threading; using Microsoft.VisualStudio.TestTools.UnitTesting; using OpenQA.Selenium.Appium; using OpenQA.Selenium.Appium.Windows; -using OpenQA.Selenium.Remote; -using OpenQA.Selenium; -using System.Threading; +using OpenQA.Selenium.Interactions; namespace PowerToysTests { @@ -20,7 +19,7 @@ private void PressWinKey() { if(!isWinKeyPressed) { - session.Keyboard.PressKey(Keys.Command); + new Actions(session).KeyDown(OpenQA.Selenium.Keys.Command).Perform(); isWinKeyPressed = true; } } @@ -29,7 +28,7 @@ private void ReleaseWinKey() { if(isWinKeyPressed) { - session.Keyboard.ReleaseKey(Keys.Command); + new Actions(session).KeyUp(OpenQA.Selenium.Keys.Command).Perform(); isWinKeyPressed = false; } } @@ -57,7 +56,7 @@ public void DisappearsOnWinKeyRelease() shortcutHelperWindow = session.FindElementByXPath("/Pane[@ClassName=\"#32769\"]/Pane[@ClassName=\"PToyD2DPopup\"]"); Assert.IsNotNull(shortcutHelperWindow); } - catch (InvalidOperationException ex) + catch (InvalidOperationException) { // Not the exception we wanted to catch here. Assert.Fail("Shortcut Guide not found"); @@ -90,7 +89,7 @@ public void DoesNotSpawnStartMenuOnLongPress() // FindElementByClassName will be faster than using with XPath. WindowsElement shortcutHelperWindow = session.FindElementByClassName("PToyD2DPopup"); Assert.IsNotNull(shortcutHelperWindow); - } catch (InvalidOperationException ex) + } catch (InvalidOperationException) { // Not the exception we wanted to catch here. Assert.Fail("Shortcut Guide not found"); @@ -119,7 +118,7 @@ public void TestInitialize() try { startMenuWindow = session.FindElementByXPath("/Pane[@ClassName=\"#32769\"]/Window[@Name=\"Start\"]"); - } catch (Exception ex) + } catch (Exception) { //Start menu not found, as expected. } @@ -133,7 +132,7 @@ public void TestInitialize() WindowsDriver startMenuSession = new WindowsDriver(new Uri(WindowsApplicationDriverUrl), appiumOptions); if (startMenuSession != null) { - startMenuSession.Keyboard.SendKeys(OpenQA.Selenium.Keys.Escape + OpenQA.Selenium.Keys.Escape); + new Actions(session).SendKeys(OpenQA.Selenium.Keys.Escape + OpenQA.Selenium.Keys.Escape).Perform(); startMenuSession.Quit(); } } From f2d54ba19138909855c9d080164d88825d0bb86e Mon Sep 17 00:00:00 2001 From: Serafima Zykova Date: Mon, 16 Mar 2020 16:34:13 +0300 Subject: [PATCH 30/33] added editor tests file --- .../FancyZonesTests/EditorTests.cs | 53 +++++++++++++++++++ .../win-app-driver/win-app-driver.csproj | 1 + 2 files changed, 54 insertions(+) create mode 100644 src/tests/win-app-driver/FancyZonesTests/EditorTests.cs diff --git a/src/tests/win-app-driver/FancyZonesTests/EditorTests.cs b/src/tests/win-app-driver/FancyZonesTests/EditorTests.cs new file mode 100644 index 000000000000..de9a661278d1 --- /dev/null +++ b/src/tests/win-app-driver/FancyZonesTests/EditorTests.cs @@ -0,0 +1,53 @@ +using Microsoft.VisualStudio.TestTools.UnitTesting; +using OpenQA.Selenium.Appium.Windows; + +namespace PowerToysTests +{ + [TestClass] + public class FancyZonesEditorTests : PowerToysSession + { + [TestMethod] + public void OpenEditorBySettingsButton() + { + OpenFancyZonesSettings(); + + WindowsElement editorButton = session.FindElementByXPath("//Button[@Name=\"Edit zones\"]"); + Assert.IsNotNull(editorButton); + + editorButton.Click(); + ShortWait(); + + WindowsElement editorWindow = session.FindElementByXPath("//Window[@Name=\"FancyZones Editor\"]"); + Assert.IsNotNull(editorWindow); + + //Close editor + session.FindElementByAccessibilityId("PART_Close").Click(); + } + + [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/win-app-driver.csproj b/src/tests/win-app-driver/win-app-driver.csproj index adee49eaf145..c71426ccbbfb 100644 --- a/src/tests/win-app-driver/win-app-driver.csproj +++ b/src/tests/win-app-driver/win-app-driver.csproj @@ -83,6 +83,7 @@ + From ce3f1fb5e861a2042722451c1c3a1b240281d7b8 Mon Sep 17 00:00:00 2001 From: Serafima Zykova Date: Mon, 16 Mar 2020 16:34:39 +0300 Subject: [PATCH 31/33] moved fancy zones opening method --- .../FancyZonesTests/FancyZonesSettingsTests.cs | 11 ----------- src/tests/win-app-driver/PowerToysSession.cs | 11 +++++++++++ 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/tests/win-app-driver/FancyZonesTests/FancyZonesSettingsTests.cs b/src/tests/win-app-driver/FancyZonesTests/FancyZonesSettingsTests.cs index 0fad8657100f..e4fdae5d0525 100644 --- a/src/tests/win-app-driver/FancyZonesTests/FancyZonesSettingsTests.cs +++ b/src/tests/win-app-driver/FancyZonesTests/FancyZonesSettingsTests.cs @@ -43,17 +43,6 @@ private static void Init() Assert.IsNotNull(_scrollDown); } - private static void OpenFancyZonesSettings() - { - WindowsElement fzNavigationButton = session.FindElementByXPath("//Button[@Name=\"FancyZones\"]"); - Assert.IsNotNull(fzNavigationButton); - - fzNavigationButton.Click(); - fzNavigationButton.Click(); - - ShortWait(); - } - private JObject getProperties() { JObject settings = JObject.Parse(File.ReadAllText(_settingsPath)); diff --git a/src/tests/win-app-driver/PowerToysSession.cs b/src/tests/win-app-driver/PowerToysSession.cs index 7fc218347639..2209ebb049ce 100644 --- a/src/tests/win-app-driver/PowerToysSession.cs +++ b/src/tests/win-app-driver/PowerToysSession.cs @@ -57,6 +57,17 @@ public static void OpenSettings() trayButton.Click(); } + public static void OpenFancyZonesSettings() + { + WindowsElement fzNavigationButton = session.FindElementByXPath("//Button[@Name=\"FancyZones\"]"); + Assert.IsNotNull(fzNavigationButton); + + fzNavigationButton.Click(); + fzNavigationButton.Click(); + + ShortWait(); + } + public static void CloseSettings() { WindowsElement settings = session.FindElementByName("PowerToys Settings"); From ded64402de0687f27571530bdcb8dd3d031d2c96 Mon Sep 17 00:00:00 2001 From: Serafima Date: Tue, 17 Mar 2020 13:12:27 +0300 Subject: [PATCH 32/33] moved settings restore to base class --- .../FancyZonesSettingsTests.cs | 77 +++++++------------ src/tests/win-app-driver/PowerToysSession.cs | 17 ++++ 2 files changed, 45 insertions(+), 49 deletions(-) diff --git a/src/tests/win-app-driver/FancyZonesTests/FancyZonesSettingsTests.cs b/src/tests/win-app-driver/FancyZonesTests/FancyZonesSettingsTests.cs index e4fdae5d0525..b7b4e75633cb 100644 --- a/src/tests/win-app-driver/FancyZonesTests/FancyZonesSettingsTests.cs +++ b/src/tests/win-app-driver/FancyZonesTests/FancyZonesSettingsTests.cs @@ -14,9 +14,7 @@ namespace PowerToysTests { [TestClass] public class FancyZonesSettingsTests : PowerToysSession - { - private static string _settingsPath = ""; - private string _initialSettings = ""; + { private JObject _initialSettingsJson; private static WindowsElement _saveButton; @@ -41,12 +39,19 @@ private static void Init() _scrollDown = new Actions(session).MoveToElement(_saveButton).MoveByOffset(0, _saveButton.Rect.Height).ContextClick() .SendKeys(OpenQA.Selenium.Keys.PageDown + OpenQA.Selenium.Keys.PageDown); Assert.IsNotNull(_scrollDown); - } - - private JObject getProperties() - { - JObject settings = JObject.Parse(File.ReadAllText(_settingsPath)); - return settings["properties"].ToObject(); + } + + private JObject getProperties() + { + try + { + JObject settings = JObject.Parse(File.ReadAllText(_settingsPath)); + return settings["properties"].ToObject(); + } + catch (Newtonsoft.Json.JsonReaderException) + { + return new JObject(); + } } private T getPropertyValue(string propertyName) @@ -226,19 +231,7 @@ public void FancyZonesSettingsOpen() WindowsElement fzTitle = session.FindElementByName("FancyZones Settings"); Assert.IsNotNull(fzTitle); } - /* - [TestMethod] - public void EditorOpen() - { - session.FindElementByXPath("//Button[@Name=\"Edit zones\"]").Click(); - ShortWait(); - WindowsElement editorWindow = session.FindElementByName("FancyZones Editor"); - Assert.IsNotNull(editorWindow); - - editorWindow.SendKeys(OpenQA.Selenium.Keys.Alt + OpenQA.Selenium.Keys.F4); - } - */ /* * click each toggle, * save changes, @@ -710,14 +703,6 @@ public void ConfigureLocalSymbolHotkey() public static void ClassInitialize(TestContext context) { Setup(context); - - string settingsFolderPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Microsoft/PowerToys/FancyZones"); - if (!Directory.Exists(settingsFolderPath)) - { - Directory.CreateDirectory(settingsFolderPath); - } - _settingsPath = settingsFolderPath + "/settings.json"; - Init(); } @@ -740,31 +725,25 @@ public static void ClassCleanup() } TearDown(); - } - - [TestInitialize] - public void TestInitialize() - { - try - { - _initialSettings = File.ReadAllText(_settingsPath); - _initialSettingsJson = JObject.Parse(_initialSettings); - } - catch (System.IO.FileNotFoundException) - { - _initialSettings = ""; - } + } + + [TestInitialize] + public void TestInitialize() + { + try + { + _initialSettingsJson = JObject.Parse(_initialSettings); + } + catch (Newtonsoft.Json.JsonReaderException) + { + //empty settings + } } [TestCleanup] public void TestCleanup() { - ScrollUp(); - - if (_initialSettings.Length > 0) - { - File.WriteAllText(_settingsPath, _initialSettings); - } + ScrollUp(); } } } diff --git a/src/tests/win-app-driver/PowerToysSession.cs b/src/tests/win-app-driver/PowerToysSession.cs index 2209ebb049ce..c4c26b8544c0 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.IO; using System.Threading; using Microsoft.VisualStudio.TestTools.UnitTesting; using OpenQA.Selenium.Appium; @@ -14,8 +15,18 @@ public class PowerToysSession protected static bool isPowerToysLaunched = false; protected static WindowsElement trayButton; + protected static string _settingsPath = ""; + protected static string _initialSettings = ""; + public static void Setup(TestContext context) { + //read settings before running tests to restore them after + _settingsPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Microsoft/PowerToys/FancyZones/settings.json"); + if (Directory.Exists(_settingsPath)) + { + _initialSettings = File.ReadAllText(_settingsPath); + } + if (session == null) { // Create a new Desktop session to use PowerToys. @@ -43,6 +54,12 @@ public static void TearDown() session.Quit(); session = null; } + + //restore initial settings file + if (_initialSettings.Length > 0) + { + File.WriteAllText(_settingsPath, _initialSettings); + } } public static void ShortWait() From 6e2e89c02895e672e0d412531164844ba055ddd5 Mon Sep 17 00:00:00 2001 From: Yevhenii Holovachov Date: Tue, 17 Mar 2020 17:32:31 +0200 Subject: [PATCH 33/33] Added test method for Fancy Zones count --- .../FancyZonesTests/EditorTests.cs | 51 ++++++++++++++++++- src/tests/win-app-driver/PowerToysSession.cs | 5 ++ 2 files changed, 55 insertions(+), 1 deletion(-) diff --git a/src/tests/win-app-driver/FancyZonesTests/EditorTests.cs b/src/tests/win-app-driver/FancyZonesTests/EditorTests.cs index de9a661278d1..01bd57572275 100644 --- a/src/tests/win-app-driver/FancyZonesTests/EditorTests.cs +++ b/src/tests/win-app-driver/FancyZonesTests/EditorTests.cs @@ -1,4 +1,6 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using OpenQA.Selenium; using OpenQA.Selenium.Appium.Windows; namespace PowerToysTests @@ -24,6 +26,53 @@ public void OpenEditorBySettingsButton() session.FindElementByAccessibilityId("PART_Close").Click(); } + [TestMethod] + public void ZoneCount() + { + + WaitSeconds(1); + + OpenFancyZonesSettings(); + + WaitSeconds(1); + + WindowsElement editorButton = session.FindElementByXPath("//Button[@Name=\"Edit zones\"]"); + Assert.IsNotNull(editorButton); + editorButton.Click(); + + WaitSeconds(1); + + WindowsElement minusButton = session.FindElementByAccessibilityId("decrementZones"); + Assert.IsNotNull(minusButton); + + WindowsElement plusButton = session.FindElementByAccessibilityId("incrementZones"); + Assert.IsNotNull(plusButton); + + WindowsElement zoneCount = session.FindElementByAccessibilityId("zoneCount"); + Assert.IsNotNull(zoneCount); + + int zoneCountQty; + Assert.IsTrue(Int32.TryParse(zoneCount.Text, out zoneCountQty)); + + for (int i = zoneCountQty; i > -5; --i) + { + Assert.IsTrue(Int32.TryParse(zoneCount.Text, out zoneCountQty)); + Assert.AreEqual(Math.Max(i, 1), zoneCountQty); + minusButton.Click(); + } + + for (int i = 1; i < 45; ++i) + { + Assert.IsTrue(Int32.TryParse(zoneCount.Text, out zoneCountQty)); + Assert.AreEqual(Math.Min(i, 40), zoneCountQty); + plusButton.Click(); + } + + WindowsElement mainWindow = session.FindElementByAccessibilityId("MainWindow1"); + Assert.IsNotNull(mainWindow); + mainWindow.SendKeys(Keys.Alt + Keys.F4); + } + [ClassInitialize] public static void ClassInitialize(TestContext context) { diff --git a/src/tests/win-app-driver/PowerToysSession.cs b/src/tests/win-app-driver/PowerToysSession.cs index c4c26b8544c0..a07a7b8e7f82 100644 --- a/src/tests/win-app-driver/PowerToysSession.cs +++ b/src/tests/win-app-driver/PowerToysSession.cs @@ -62,6 +62,11 @@ public static void TearDown() } } + public static void WaitSeconds(int seconds) + { + Thread.Sleep(TimeSpan.FromSeconds(seconds)); + } + public static void ShortWait() { Thread.Sleep(TimeSpan.FromSeconds(0.5));