mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-06-07 09:28:03 +08:00
[WinAppDriver tests] Affection on user setting files fix (#4186)
This commit is contained in:
parent
c78e6588ad
commit
90efc5740f
@ -224,6 +224,7 @@ namespace JSONHelpers
|
|||||||
{
|
{
|
||||||
std::wstring result = PTSettingsHelper::get_module_save_folder_location(moduleName);
|
std::wstring result = PTSettingsHelper::get_module_save_folder_location(moduleName);
|
||||||
jsonFilePath = result + L"\\" + std::wstring(L"zones-settings.json");
|
jsonFilePath = result + L"\\" + std::wstring(L"zones-settings.json");
|
||||||
|
appZoneHistoryFilePath = result + L"\\" + std::wstring(L"app-zone-history.json");
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -261,6 +261,9 @@ namespace PowerToysTests
|
|||||||
public static void ClassInitialize(TestContext context)
|
public static void ClassInitialize(TestContext context)
|
||||||
{
|
{
|
||||||
Setup(context, false);
|
Setup(context, false);
|
||||||
|
if (session == null)
|
||||||
|
return;
|
||||||
|
|
||||||
ResetSettings();
|
ResetSettings();
|
||||||
|
|
||||||
if (!isPowerToysLaunched)
|
if (!isPowerToysLaunched)
|
||||||
@ -281,6 +284,9 @@ namespace PowerToysTests
|
|||||||
[TestInitialize]
|
[TestInitialize]
|
||||||
public void TestInitialize()
|
public void TestInitialize()
|
||||||
{
|
{
|
||||||
|
if (session == null)
|
||||||
|
return;
|
||||||
|
|
||||||
//create canvas zone
|
//create canvas zone
|
||||||
OpenCreatorWindow("Create new custom", "Custom layout creator");
|
OpenCreatorWindow("Create new custom", "Custom layout creator");
|
||||||
session.FindElementByAccessibilityId("newZoneButton").Click();
|
session.FindElementByAccessibilityId("newZoneButton").Click();
|
||||||
@ -289,6 +295,9 @@ namespace PowerToysTests
|
|||||||
[TestCleanup]
|
[TestCleanup]
|
||||||
public void TestCleanup()
|
public void TestCleanup()
|
||||||
{
|
{
|
||||||
|
if (session == null)
|
||||||
|
return;
|
||||||
|
|
||||||
new Actions(session).MoveToElement(session.FindElementByXPath("//Button[@Name=\"Cancel\"]")).Click().Perform();
|
new Actions(session).MoveToElement(session.FindElementByXPath("//Button[@Name=\"Cancel\"]")).Click().Perform();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -292,6 +292,9 @@ namespace PowerToysTests
|
|||||||
public static void ClassInitialize(TestContext context)
|
public static void ClassInitialize(TestContext context)
|
||||||
{
|
{
|
||||||
Setup(context, false);
|
Setup(context, false);
|
||||||
|
if (session == null)
|
||||||
|
return;
|
||||||
|
|
||||||
ResetSettings();
|
ResetSettings();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -304,6 +307,9 @@ namespace PowerToysTests
|
|||||||
[TestInitialize]
|
[TestInitialize]
|
||||||
public void TestInitialize()
|
public void TestInitialize()
|
||||||
{
|
{
|
||||||
|
if (session == null)
|
||||||
|
return;
|
||||||
|
|
||||||
if (!isPowerToysLaunched)
|
if (!isPowerToysLaunched)
|
||||||
{
|
{
|
||||||
LaunchPowerToys();
|
LaunchPowerToys();
|
||||||
|
@ -397,6 +397,9 @@ namespace PowerToysTests
|
|||||||
public static void ClassInitialize(TestContext context)
|
public static void ClassInitialize(TestContext context)
|
||||||
{
|
{
|
||||||
Setup(context, false);
|
Setup(context, false);
|
||||||
|
if (session == null)
|
||||||
|
return;
|
||||||
|
|
||||||
ResetSettings();
|
ResetSettings();
|
||||||
|
|
||||||
if (!isPowerToysLaunched)
|
if (!isPowerToysLaunched)
|
||||||
|
@ -233,6 +233,9 @@ namespace PowerToysTests
|
|||||||
public static void ClassInitialize(TestContext context)
|
public static void ClassInitialize(TestContext context)
|
||||||
{
|
{
|
||||||
Setup(context, false);
|
Setup(context, false);
|
||||||
|
if (session == null)
|
||||||
|
return;
|
||||||
|
|
||||||
ResetDefaultFancyZonesSettings(true);
|
ResetDefaultFancyZonesSettings(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||||
@ -179,6 +179,9 @@ namespace PowerToysTests
|
|||||||
public static void ClassInitialize(TestContext context)
|
public static void ClassInitialize(TestContext context)
|
||||||
{
|
{
|
||||||
Setup(context, false);
|
Setup(context, false);
|
||||||
|
if (session == null)
|
||||||
|
return;
|
||||||
|
|
||||||
ResetSettings();
|
ResetSettings();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -68,6 +68,9 @@ namespace PowerToysTests
|
|||||||
public static void ClassInitialize(TestContext context)
|
public static void ClassInitialize(TestContext context)
|
||||||
{
|
{
|
||||||
Setup(context, false);
|
Setup(context, false);
|
||||||
|
if (session == null)
|
||||||
|
return;
|
||||||
|
|
||||||
ResetDefaultFancyZonesSettings(true);
|
ResetDefaultFancyZonesSettings(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -81,6 +84,9 @@ namespace PowerToysTests
|
|||||||
[TestInitialize]
|
[TestInitialize]
|
||||||
public void TestInitialize()
|
public void TestInitialize()
|
||||||
{
|
{
|
||||||
|
if (session == null)
|
||||||
|
return;
|
||||||
|
|
||||||
OpenEditor();
|
OpenEditor();
|
||||||
OpenTemplates();
|
OpenTemplates();
|
||||||
}
|
}
|
||||||
|
@ -157,6 +157,9 @@ namespace PowerToysTests
|
|||||||
public static void ClassInitialize(TestContext context)
|
public static void ClassInitialize(TestContext context)
|
||||||
{
|
{
|
||||||
Setup(context, false);
|
Setup(context, false);
|
||||||
|
if (session == null)
|
||||||
|
return;
|
||||||
|
|
||||||
ResetDefaultFancyZonesSettings(false);
|
ResetDefaultFancyZonesSettings(false);
|
||||||
ResetDefaultZoneSettings(true);
|
ResetDefaultZoneSettings(true);
|
||||||
}
|
}
|
||||||
@ -171,6 +174,9 @@ namespace PowerToysTests
|
|||||||
[TestInitialize]
|
[TestInitialize]
|
||||||
public void TestInitialize()
|
public void TestInitialize()
|
||||||
{
|
{
|
||||||
|
if (session == null)
|
||||||
|
return;
|
||||||
|
|
||||||
if (!isPowerToysLaunched)
|
if (!isPowerToysLaunched)
|
||||||
{
|
{
|
||||||
LaunchPowerToys();
|
LaunchPowerToys();
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||||
using OpenQA.Selenium.Appium.Windows;
|
using OpenQA.Selenium.Appium.Windows;
|
||||||
using OpenQA.Selenium.Interactions;
|
using OpenQA.Selenium.Interactions;
|
||||||
|
using System;
|
||||||
|
|
||||||
namespace PowerToysTests
|
namespace PowerToysTests
|
||||||
{
|
{
|
||||||
@ -16,13 +17,20 @@ namespace PowerToysTests
|
|||||||
|
|
||||||
protected static void OpenEditor()
|
protected static void OpenEditor()
|
||||||
{
|
{
|
||||||
new Actions(session).KeyDown(OpenQA.Selenium.Keys.Command).SendKeys("`").KeyUp(OpenQA.Selenium.Keys.Command).Perform();
|
try
|
||||||
WaitSeconds(2);
|
{
|
||||||
//editorWindow = WaitElementByXPath("//Window[@Name=\"FancyZones Editor\"]");
|
new Actions(session).KeyDown(OpenQA.Selenium.Keys.Command).SendKeys("`").KeyUp(OpenQA.Selenium.Keys.Command).Perform();
|
||||||
editorWindow = WaitElementByName("FancyZones Editor");
|
WaitSeconds(2);
|
||||||
//may not find editor by name in 0.16.1
|
//editorWindow = WaitElementByXPath("//Window[@Name=\"FancyZones Editor\"]");
|
||||||
//editorWindow = WaitElementByAccessibilityId("MainWindow1");
|
editorWindow = WaitElementByName("FancyZones Editor");
|
||||||
Assert.IsNotNull(editorWindow, "Couldn't find editor window");
|
//may not find editor by name in 0.16.1
|
||||||
|
//editorWindow = WaitElementByAccessibilityId("MainWindow1");
|
||||||
|
Assert.IsNotNull(editorWindow, "Couldn't find editor window");
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Console.WriteLine(ex.Message);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static void CloseEditor()
|
protected static void CloseEditor()
|
||||||
@ -42,28 +50,49 @@ namespace PowerToysTests
|
|||||||
|
|
||||||
protected static void OpenCustomLayouts()
|
protected static void OpenCustomLayouts()
|
||||||
{
|
{
|
||||||
WindowsElement customsTab = session.FindElementByName("Custom");
|
try
|
||||||
customsTab.Click();
|
{
|
||||||
string isSelected = customsTab.GetAttribute("SelectionItem.IsSelected");
|
WindowsElement customsTab = session.FindElementByName("Custom");
|
||||||
Assert.AreEqual("True", isSelected, "Custom tab cannot be opened");
|
customsTab.Click();
|
||||||
|
string isSelected = customsTab.GetAttribute("SelectionItem.IsSelected");
|
||||||
|
Assert.AreEqual("True", isSelected, "Custom tab cannot be opened");
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Console.WriteLine(ex.Message);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static void OpenTemplates()
|
protected static void OpenTemplates()
|
||||||
{
|
{
|
||||||
WindowsElement templatesTab = session.FindElementByName("Templates");
|
try
|
||||||
templatesTab.Click();
|
{
|
||||||
string isSelected = templatesTab.GetAttribute("SelectionItem.IsSelected");
|
WindowsElement templatesTab = session.FindElementByName("Templates");
|
||||||
Assert.AreEqual("True", isSelected, "Templates tab cannot be opened");
|
templatesTab.Click();
|
||||||
|
string isSelected = templatesTab.GetAttribute("SelectionItem.IsSelected");
|
||||||
|
Assert.AreEqual("True", isSelected, "Templates tab cannot be opened");
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Console.WriteLine(ex.Message);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static void OpenCreatorWindow(string tabName, string creatorWindowName, string buttonId = "EditCustomButton")
|
protected static void OpenCreatorWindow(string tabName, string creatorWindowName, string buttonId = "EditCustomButton")
|
||||||
{
|
{
|
||||||
string elementXPath = "//Text[@Name=\"" + tabName + "\"]";
|
try
|
||||||
WaitElementByXPath(elementXPath).Click();
|
{
|
||||||
WaitElementByAccessibilityId(buttonId).Click();
|
string elementXPath = "//Text[@Name=\"" + tabName + "\"]";
|
||||||
|
WaitElementByXPath(elementXPath).Click();
|
||||||
|
WaitElementByAccessibilityId(buttonId).Click();
|
||||||
|
|
||||||
WindowsElement creatorWindow = WaitElementByName(creatorWindowName);
|
WindowsElement creatorWindow = WaitElementByName(creatorWindowName);
|
||||||
Assert.IsNotNull(creatorWindow, "Creator window didn't open");
|
Assert.IsNotNull(creatorWindow, "Creator window didn't open");
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Console.WriteLine(ex.Message);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void ZoneCountTest(int canvasZoneCount, int gridZoneCount)
|
protected void ZoneCountTest(int canvasZoneCount, int gridZoneCount)
|
||||||
|
@ -713,6 +713,9 @@ namespace PowerToysTests
|
|||||||
public static void ClassInitialize(TestContext context)
|
public static void ClassInitialize(TestContext context)
|
||||||
{
|
{
|
||||||
Setup(context);
|
Setup(context);
|
||||||
|
if (session == null)
|
||||||
|
return;
|
||||||
|
|
||||||
Init();
|
Init();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -740,6 +743,9 @@ namespace PowerToysTests
|
|||||||
[TestInitialize]
|
[TestInitialize]
|
||||||
public void TestInitialize()
|
public void TestInitialize()
|
||||||
{
|
{
|
||||||
|
if (session == null)
|
||||||
|
return;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
_initialSettingsJson = JObject.Parse(_initialSettings);
|
_initialSettingsJson = JObject.Parse(_initialSettings);
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||||
@ -22,155 +22,175 @@ namespace PowerToysTests
|
|||||||
protected static string _settingsFolderPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Microsoft\\PowerToys\\FancyZones");
|
protected static string _settingsFolderPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Microsoft\\PowerToys\\FancyZones");
|
||||||
protected static string _settingsPath = _settingsFolderPath + "\\settings.json";
|
protected static string _settingsPath = _settingsFolderPath + "\\settings.json";
|
||||||
protected static string _zoneSettingsPath = _settingsFolderPath + "\\zones-settings.json";
|
protected static string _zoneSettingsPath = _settingsFolderPath + "\\zones-settings.json";
|
||||||
|
protected static string _appHistoryPath = _settingsFolderPath + "\\app-zone-history.json";
|
||||||
|
|
||||||
protected static string _initialSettings = "";
|
protected static string _initialSettings = "";
|
||||||
protected static string _initialZoneSettings = "";
|
protected static string _initialZoneSettings = "";
|
||||||
|
protected static string _initialAppHistorySettings = "";
|
||||||
|
|
||||||
protected const string _defaultSettings = "{\"version\":\"1.0\",\"name\":\"FancyZones\",\"properties\":{\"fancyzones_shiftDrag\":{\"value\":true},\"fancyzones_mouseSwitch\":{\"value\":false},\"fancyzones_overrideSnapHotkeys\":{\"value\":false},\"fancyzones_moveWindowAcrossMonitors\":{\"value\":false},\"fancyzones_zoneSetChange_flashZones\":{\"value\":false},\"fancyzones_displayChange_moveWindows\":{\"value\":false},\"fancyzones_zoneSetChange_moveWindows\":{\"value\":false},\"fancyzones_appLastZone_moveWindows\":{\"value\":false},\"use_cursorpos_editor_startupscreen\":{\"value\":true},\"fancyzones_zoneHighlightColor\":{\"value\":\"#0078D7\"},\"fancyzones_highlight_opacity\":{\"value\":90},\"fancyzones_editor_hotkey\":{\"value\":{\"win\":true,\"ctrl\":false,\"alt\":false,\"shift\":false,\"code\":192,\"key\":\"`\"}},\"fancyzones_excluded_apps\":{\"value\":\"\"}}}";
|
protected const string _defaultSettings = "{\"version\":\"1.0\",\"name\":\"FancyZones\",\"properties\":{\"fancyzones_shiftDrag\":{\"value\":true},\"fancyzones_mouseSwitch\":{\"value\":false},\"fancyzones_overrideSnapHotkeys\":{\"value\":false},\"fancyzones_moveWindowAcrossMonitors\":{\"value\":false},\"fancyzones_zoneSetChange_flashZones\":{\"value\":false},\"fancyzones_displayChange_moveWindows\":{\"value\":false},\"fancyzones_zoneSetChange_moveWindows\":{\"value\":false},\"fancyzones_appLastZone_moveWindows\":{\"value\":false},\"use_cursorpos_editor_startupscreen\":{\"value\":true},\"fancyzones_zoneHighlightColor\":{\"value\":\"#0078D7\"},\"fancyzones_highlight_opacity\":{\"value\":90},\"fancyzones_editor_hotkey\":{\"value\":{\"win\":true,\"ctrl\":false,\"alt\":false,\"shift\":false,\"code\":192,\"key\":\"`\"}},\"fancyzones_excluded_apps\":{\"value\":\"\"}}}";
|
||||||
protected const string _defaultZoneSettings = "{\"app-zone-history\":[],\"devices\":[],\"custom-zone-sets\":[]}";
|
protected const string _defaultZoneSettings = "{\"app-zone-history\":[],\"devices\":[],\"custom-zone-sets\":[]}";
|
||||||
|
|
||||||
|
|
||||||
public static void Setup(TestContext context, bool isLaunchRequired = true)
|
public static void Setup(TestContext context, bool isLaunchRequired = true)
|
||||||
{
|
{
|
||||||
ReadUserSettings(); //read settings before running tests to restore them after
|
|
||||||
|
|
||||||
if (session == null)
|
if (session == null)
|
||||||
{
|
{
|
||||||
|
ReadUserSettings(); //read settings before running tests to restore them after
|
||||||
|
|
||||||
// Create a new Desktop session to use PowerToys.
|
// Create a new Desktop session to use PowerToys.
|
||||||
AppiumOptions appiumOptions = new AppiumOptions();
|
AppiumOptions appiumOptions = new AppiumOptions();
|
||||||
appiumOptions.PlatformName = "Windows";
|
appiumOptions.PlatformName = "Windows";
|
||||||
appiumOptions.AddAdditionalCapability("app", "Root");
|
appiumOptions.AddAdditionalCapability("app", "Root");
|
||||||
session = new WindowsDriver<WindowsElement>(new Uri(WindowsApplicationDriverUrl), appiumOptions);
|
try
|
||||||
Assert.IsNotNull(session);
|
|
||||||
|
|
||||||
trayButton = session.FindElementByAccessibilityId("1502");
|
|
||||||
|
|
||||||
isPowerToysLaunched = CheckPowerToysLaunched();
|
|
||||||
if (!isPowerToysLaunched && isLaunchRequired)
|
|
||||||
{
|
{
|
||||||
LaunchPowerToys();
|
session = new WindowsDriver<WindowsElement>(new Uri(WindowsApplicationDriverUrl), appiumOptions);
|
||||||
|
trayButton = session.FindElementByAccessibilityId("1502");
|
||||||
|
|
||||||
|
isPowerToysLaunched = CheckPowerToysLaunched();
|
||||||
|
if (!isPowerToysLaunched && isLaunchRequired)
|
||||||
|
{
|
||||||
|
LaunchPowerToys();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Console.WriteLine(ex.Message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void TearDown()
|
public static void TearDown()
|
||||||
{
|
{
|
||||||
RestoreUserSettings(); //restore initial settings files
|
RestoreUserSettings(); //restore initial settings files
|
||||||
|
|
||||||
if (session != null)
|
if (session != null)
|
||||||
{
|
{
|
||||||
session.Quit();
|
session.Quit();
|
||||||
session = null;
|
session = null;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public static void WaitSeconds(double seconds)
|
|
||||||
{
|
|
||||||
Thread.Sleep(TimeSpan.FromSeconds(seconds));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//Trying to find element by XPath
|
public static void WaitSeconds(double seconds)
|
||||||
protected static WindowsElement WaitElementByName(string name, double maxTime = 10)
|
{
|
||||||
{
|
Thread.Sleep(TimeSpan.FromSeconds(seconds));
|
||||||
WindowsElement result = null;
|
}
|
||||||
Stopwatch timer = new Stopwatch();
|
|
||||||
timer.Start();
|
//Trying to find element by XPath
|
||||||
while (timer.Elapsed < TimeSpan.FromSeconds(maxTime))
|
protected static WindowsElement WaitElementByName(string name, double maxTime = 10)
|
||||||
{
|
{
|
||||||
try
|
WindowsElement result = null;
|
||||||
{
|
Stopwatch timer = new Stopwatch();
|
||||||
result = session.FindElementByName(name);
|
timer.Start();
|
||||||
}
|
while (timer.Elapsed < TimeSpan.FromSeconds(maxTime))
|
||||||
catch { }
|
{
|
||||||
return result;
|
try
|
||||||
}
|
{
|
||||||
return null;
|
result = session.FindElementByName(name);
|
||||||
}
|
}
|
||||||
|
catch { }
|
||||||
//Trying to find element by XPath
|
return result;
|
||||||
protected static WindowsElement WaitElementByXPath(string xPath, double maxTime = 10)
|
}
|
||||||
{
|
return null;
|
||||||
WindowsElement result = null;
|
}
|
||||||
Stopwatch timer = new Stopwatch();
|
|
||||||
timer.Start();
|
//Trying to find element by XPath
|
||||||
while (timer.Elapsed < TimeSpan.FromSeconds(maxTime))
|
protected static WindowsElement WaitElementByXPath(string xPath, double maxTime = 10)
|
||||||
{
|
{
|
||||||
try
|
WindowsElement result = null;
|
||||||
{
|
Stopwatch timer = new Stopwatch();
|
||||||
result = session.FindElementByXPath(xPath);
|
timer.Start();
|
||||||
}
|
while (timer.Elapsed < TimeSpan.FromSeconds(maxTime))
|
||||||
catch { }
|
{
|
||||||
return result;
|
try
|
||||||
}
|
{
|
||||||
return null;
|
result = session.FindElementByXPath(xPath);
|
||||||
}
|
}
|
||||||
|
catch { }
|
||||||
//Trying to find element by AccessibilityId
|
return result;
|
||||||
protected static WindowsElement WaitElementByAccessibilityId(string accessibilityId, double maxTime = 10)
|
}
|
||||||
{
|
return null;
|
||||||
WindowsElement result = null;
|
}
|
||||||
Stopwatch timer = new Stopwatch();
|
|
||||||
timer.Start();
|
//Trying to find element by AccessibilityId
|
||||||
while (timer.Elapsed < TimeSpan.FromSeconds(maxTime))
|
protected static WindowsElement WaitElementByAccessibilityId(string accessibilityId, double maxTime = 10)
|
||||||
{
|
{
|
||||||
try
|
WindowsElement result = null;
|
||||||
{
|
Stopwatch timer = new Stopwatch();
|
||||||
result = session.FindElementByAccessibilityId(accessibilityId);
|
timer.Start();
|
||||||
}
|
while (timer.Elapsed < TimeSpan.FromSeconds(maxTime))
|
||||||
catch { }
|
{
|
||||||
return result;
|
try
|
||||||
}
|
{
|
||||||
return null;
|
result = session.FindElementByAccessibilityId(accessibilityId);
|
||||||
|
}
|
||||||
|
catch { }
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void OpenSettings()
|
public static void OpenSettings()
|
||||||
{
|
{
|
||||||
trayButton.Click();
|
try
|
||||||
session.FindElementByXPath("//Button[@Name=\"PowerToys\"]").Click();
|
{
|
||||||
trayButton.Click();
|
trayButton.Click();
|
||||||
|
session.FindElementByXPath("//Button[@Name=\"PowerToys\"]").Click();
|
||||||
|
trayButton.Click();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Console.WriteLine(ex.Message);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void OpenFancyZonesSettings()
|
public static void OpenFancyZonesSettings()
|
||||||
{
|
{
|
||||||
WindowsElement fzNavigationButton = WaitElementByXPath("//Button[@Name=\"FancyZones\"]");
|
try
|
||||||
Assert.IsNotNull(fzNavigationButton);
|
{
|
||||||
|
WindowsElement fzNavigationButton = WaitElementByXPath("//Button[@Name=\"FancyZones\"]");
|
||||||
|
Assert.IsNotNull(fzNavigationButton);
|
||||||
|
|
||||||
fzNavigationButton.Click();
|
fzNavigationButton.Click();
|
||||||
fzNavigationButton.Click();
|
fzNavigationButton.Click();
|
||||||
}
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Console.WriteLine(ex.Message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static void CloseSettings()
|
public static void CloseSettings()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
WindowsElement settings = session.FindElementByName("PowerToys Settings");
|
WindowsElement settings = session.FindElementByName("PowerToys Settings");
|
||||||
if (settings != null)
|
if (settings != null)
|
||||||
{
|
{
|
||||||
settings.SendKeys(Keys.Alt + Keys.F4);
|
settings.SendKeys(Keys.Alt + Keys.F4);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch(Exception)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
Console.WriteLine(ex.Message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static bool CheckPowerToysLaunched()
|
private static bool CheckPowerToysLaunched()
|
||||||
{
|
{
|
||||||
trayButton.Click();
|
|
||||||
bool isLaunched = false;
|
bool isLaunched = false;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
trayButton.Click();
|
||||||
WindowsElement pt = WaitElementByXPath("//Button[@Name=\"PowerToys\"]");
|
WindowsElement pt = WaitElementByXPath("//Button[@Name=\"PowerToys\"]");
|
||||||
isLaunched = (pt != null);
|
isLaunched = (pt != null);
|
||||||
|
trayButton.Click(); //close
|
||||||
}
|
}
|
||||||
catch(OpenQA.Selenium.WebDriverException)
|
catch(OpenQA.Selenium.WebDriverException)
|
||||||
{
|
{
|
||||||
//PowerToys not found
|
//PowerToys not found
|
||||||
}
|
}
|
||||||
|
|
||||||
trayButton.Click(); //close
|
|
||||||
return isLaunched;
|
return isLaunched;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -190,93 +210,120 @@ namespace PowerToysTests
|
|||||||
{
|
{
|
||||||
Console.WriteLine("Exception on PowerToys launch:" + ex.Message);
|
Console.WriteLine("Exception on PowerToys launch:" + ex.Message);
|
||||||
//exception could be thrown even if app launched successfully
|
//exception could be thrown even if app launched successfully
|
||||||
}
|
}
|
||||||
|
|
||||||
isPowerToysLaunched = true;
|
isPowerToysLaunched = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void ExitPowerToys()
|
public static void ExitPowerToys()
|
||||||
{
|
{
|
||||||
trayButton.Click();
|
try
|
||||||
|
{
|
||||||
|
trayButton.Click();
|
||||||
|
|
||||||
WindowsElement pt = WaitElementByXPath("//Button[@Name=\"PowerToys\"]");
|
WindowsElement pt = WaitElementByXPath("//Button[@Name=\"PowerToys\"]");
|
||||||
Assert.IsNotNull(pt, "Couldn't find \'PowerToys\' button");
|
new Actions(session).MoveToElement(pt).ContextClick().Perform();
|
||||||
new Actions(session).MoveToElement(pt).ContextClick().Perform();
|
|
||||||
|
WaitElementByXPath("//MenuItem[@Name=\"Exit\"]").Click();
|
||||||
WaitElementByXPath("//MenuItem[@Name=\"Exit\"]").Click();
|
trayButton.Click(); //close tray
|
||||||
trayButton.Click(); //close tray
|
isPowerToysLaunched = false;
|
||||||
isPowerToysLaunched = false;
|
}
|
||||||
}
|
catch(Exception ex)
|
||||||
|
{
|
||||||
public static void ResetDefaultFancyZonesSettings(bool relaunch)
|
Console.WriteLine(ex.Message);
|
||||||
{
|
}
|
||||||
ResetSettings(_settingsFolderPath, _settingsPath, _defaultSettings, relaunch);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void ResetDefaultZoneSettings(bool relaunch)
|
public static void ResetDefaultFancyZonesSettings(bool relaunch)
|
||||||
{
|
{
|
||||||
ResetSettings(_settingsFolderPath, _zoneSettingsPath, _defaultZoneSettings, relaunch);
|
ResetSettings(_settingsFolderPath, _settingsPath, _defaultSettings, relaunch);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void ResetSettings(string folder, string filePath, string data, bool relaunch)
|
public static void ResetDefaultZoneSettings(bool relaunch)
|
||||||
{
|
{
|
||||||
if (!Directory.Exists(folder))
|
ResetSettings(_settingsFolderPath, _zoneSettingsPath, _defaultZoneSettings, relaunch);
|
||||||
{
|
|
||||||
Directory.CreateDirectory(folder);
|
|
||||||
}
|
|
||||||
File.WriteAllText(filePath, data);
|
|
||||||
|
|
||||||
if (isPowerToysLaunched)
|
|
||||||
{
|
|
||||||
ExitPowerToys();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (relaunch)
|
|
||||||
{
|
|
||||||
LaunchPowerToys();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void ReadUserSettings()
|
private static void ResetSettings(string folder, string filePath, string data, bool relaunch)
|
||||||
{
|
{
|
||||||
try
|
if (!Directory.Exists(folder))
|
||||||
{
|
{
|
||||||
_initialSettings = File.ReadAllText(_settingsPath);
|
Directory.CreateDirectory(folder);
|
||||||
}
|
}
|
||||||
catch (Exception)
|
File.WriteAllText(filePath, data);
|
||||||
{
|
|
||||||
//failed to read settings
|
if (isPowerToysLaunched)
|
||||||
}
|
{
|
||||||
|
ExitPowerToys();
|
||||||
try
|
}
|
||||||
{
|
|
||||||
_initialZoneSettings = File.ReadAllText(_zoneSettingsPath);
|
if (relaunch)
|
||||||
}
|
{
|
||||||
catch (Exception)
|
LaunchPowerToys();
|
||||||
{
|
}
|
||||||
//failed to read settings
|
}
|
||||||
}
|
|
||||||
}
|
private static void ReadUserSettings()
|
||||||
|
{
|
||||||
private static void RestoreUserSettings()
|
try
|
||||||
{
|
{
|
||||||
|
if (_initialSettings.Length == 0)
|
||||||
|
{
|
||||||
|
_initialSettings = File.ReadAllText(_settingsPath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception)
|
||||||
|
{ }
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (_initialZoneSettings.Length == 0)
|
||||||
|
{
|
||||||
|
_initialZoneSettings = File.ReadAllText(_zoneSettingsPath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception)
|
||||||
|
{ }
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (_initialAppHistorySettings.Length == 0)
|
||||||
|
{
|
||||||
|
_initialAppHistorySettings = File.ReadAllText(_appHistoryPath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception)
|
||||||
|
{ }
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void RestoreUserSettings()
|
||||||
|
{
|
||||||
if (_initialSettings.Length > 0)
|
if (_initialSettings.Length > 0)
|
||||||
{
|
{
|
||||||
File.WriteAllText(_settingsPath, _initialSettings);
|
File.WriteAllText(_settingsPath, _initialSettings);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
File.Delete(_settingsPath);
|
File.Delete(_settingsPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_initialZoneSettings.Length > 0)
|
if (_initialZoneSettings.Length > 0)
|
||||||
{
|
{
|
||||||
File.WriteAllText(_zoneSettingsPath, _initialZoneSettings);
|
File.WriteAllText(_zoneSettingsPath, _initialZoneSettings);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
File.Delete(_zoneSettingsPath);
|
File.Delete(_zoneSettingsPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (_initialAppHistorySettings.Length > 0)
|
||||||
|
{
|
||||||
|
File.WriteAllText(_appHistoryPath, _initialAppHistorySettings);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
File.Delete(_appHistoryPath);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||||
using OpenQA.Selenium.Appium;
|
using OpenQA.Selenium.Appium;
|
||||||
using OpenQA.Selenium.Appium.Windows;
|
using OpenQA.Selenium.Appium.Windows;
|
||||||
using OpenQA.Selenium.Interactions;
|
using OpenQA.Selenium.Interactions;
|
||||||
@ -95,6 +95,9 @@ namespace PowerToysTests
|
|||||||
[TestInitialize]
|
[TestInitialize]
|
||||||
public void TestInitialize()
|
public void TestInitialize()
|
||||||
{
|
{
|
||||||
|
if (session == null)
|
||||||
|
return;
|
||||||
|
|
||||||
isSettingsOpened = false;
|
isSettingsOpened = false;
|
||||||
isTrayOpened = false;
|
isTrayOpened = false;
|
||||||
}
|
}
|
||||||
|
@ -111,6 +111,9 @@ namespace PowerToysTests
|
|||||||
[TestInitialize]
|
[TestInitialize]
|
||||||
public void TestInitialize()
|
public void TestInitialize()
|
||||||
{
|
{
|
||||||
|
if (session == null)
|
||||||
|
return;
|
||||||
|
|
||||||
isWinKeyPressed = false;
|
isWinKeyPressed = false;
|
||||||
|
|
||||||
// If the start menu is open, close it.
|
// If the start menu is open, close it.
|
||||||
|
Loading…
Reference in New Issue
Block a user