Tests updates (#1793)

* updated tests for v0.16.0
Co-Authored-By: Yevhenii Holovachov <55396981+yevhenii44@users.noreply.github.com>
This commit is contained in:
Seraphima Zykova
2020-04-01 17:05:01 +03:00
committed by GitHub
parent b5f2c8b583
commit ea18fa95ad
4 changed files with 816 additions and 789 deletions

View File

@@ -17,29 +17,21 @@ namespace PowerToysTests
protected static bool isPowerToysLaunched = false;
protected static WindowsElement trayButton;
protected static string _settingsFolderPath = "";
protected static string _settingsPath = "";
protected static string _zoneSettingsPath = "";
protected static string _settingsFolderPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Microsoft\\PowerToys\\FancyZones");
protected static string _settingsPath = _settingsFolderPath + "\\settings.json";
protected static string _zoneSettingsPath = _settingsFolderPath + "\\zones-settings.json";
protected static string _initialSettings = "";
protected static string _initialZoneSettings = "";
public static void Setup(TestContext context, bool isLaunchRequired = true)
{
//read settings before running tests to restore them after
_settingsFolderPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Microsoft\\PowerToys\\FancyZones");
_settingsPath = _settingsFolderPath + "\\settings.json";
_zoneSettingsPath = _settingsFolderPath + "\\zones-settings.json";
try
{
_initialSettings = File.ReadAllText(_settingsPath);
_initialZoneSettings = File.ReadAllText(_zoneSettingsPath);
}
catch(Exception)
{
//failed to read settings
}
protected const string _defaultSettings = "{\"version\":\"1.0\",\"name\":\"FancyZones\",\"properties\":{\"fancyzones_shiftDrag\":{\"value\":true},\"fancyzones_overrideSnapHotkeys\":{\"value\":false},\"fancyzones_zoneSetChange_flashZones\":{\"value\":false},\"fancyzones_displayChange_moveWindows\":{\"value\":false},\"fancyzones_zoneSetChange_moveWindows\":{\"value\":false},\"fancyzones_virtualDesktopChange_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\":[]}";
public static void Setup(TestContext context, bool isLaunchRequired = true)
{
ReadUserSettings(); //read settings before running tests to restore them after
if (session == null)
{
// Create a new Desktop session to use PowerToys.
@@ -56,38 +48,20 @@ namespace PowerToysTests
{
LaunchPowerToys();
}
}
}
}
public static void TearDown()
{
//restore initial settings files
if (_initialSettings.Length > 0)
{
File.WriteAllText(_settingsPath, _initialSettings);
}
else
{
File.Delete(_settingsPath);
}
if (_initialZoneSettings.Length > 0)
{
File.WriteAllText(_zoneSettingsPath, _initialZoneSettings);
}
else
{
File.Delete(_zoneSettingsPath);
}
{
RestoreUserSettings(); //restore initial settings files
if (session != null)
{
session.Quit();
session = null;
}
}
}
public static void WaitSeconds(double seconds)
{
Thread.Sleep(TimeSpan.FromSeconds(seconds));
@@ -200,8 +174,10 @@ namespace PowerToysTests
try
{
AppiumOptions opts = new AppiumOptions();
opts.PlatformName = "Windows";
opts.AddAdditionalCapability("app", "Microsoft.PowerToys_8wekyb3d8bbwe!PowerToys");
opts.PlatformName = "Windows";
opts.AddAdditionalCapability("platformVersion", "10");
opts.AddAdditionalCapability("deviceName", "WindowsPC");
opts.AddAdditionalCapability("app", "C:/Program Files/PowerToys/PowerToys.exe");
WindowsDriver<WindowsElement> driver = new WindowsDriver<WindowsElement>(new Uri(WindowsApplicationDriverUrl), opts);
Assert.IsNotNull(driver);
@@ -232,37 +208,72 @@ namespace PowerToysTests
public static void ResetDefaultFancyZonesSettings(bool relaunch)
{
if (!Directory.Exists(_settingsFolderPath))
ResetSettings(_settingsFolderPath, _settingsPath, _defaultSettings, relaunch);
}
public static void ResetDefautZoneSettings(bool relaunch)
{
ResetSettings(_settingsFolderPath, _zoneSettingsPath, _defaultZoneSettings, relaunch);
}
private static void ResetSettings(string folder, string filePath, string data, bool relaunch)
{
if (!Directory.Exists(folder))
{
Directory.CreateDirectory(_settingsFolderPath);
Directory.CreateDirectory(folder);
}
string settings = "{\"version\":\"1.0\",\"name\":\"FancyZones\",\"properties\":{\"fancyzones_shiftDrag\":{\"value\":true},\"fancyzones_overrideSnapHotkeys\":{\"value\":false},\"fancyzones_zoneSetChange_flashZones\":{\"value\":false},\"fancyzones_displayChange_moveWindows\":{\"value\":false},\"fancyzones_zoneSetChange_moveWindows\":{\"value\":false},\"fancyzones_virtualDesktopChange_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\":\"\"}}}";
File.WriteAllText(_settingsPath, settings);
File.WriteAllText(filePath, data);
if (isPowerToysLaunched)
{
ExitPowerToys();
}
if (relaunch)
{
LaunchPowerToys();
}
}
public static void ResetDefautZoneSettings(bool relaunch)
private static void ReadUserSettings()
{
string zoneSettings = "{\"app-zone-history\":[],\"devices\":[],\"custom-zone-sets\":[]}";
File.WriteAllText(_zoneSettingsPath, zoneSettings);
if (isPowerToysLaunched)
try
{
ExitPowerToys();
_initialSettings = File.ReadAllText(_settingsPath);
}
if (relaunch)
catch (Exception)
{
LaunchPowerToys();
//failed to read settings
}
try
{
_initialZoneSettings = File.ReadAllText(_zoneSettingsPath);
}
catch (Exception)
{
//failed to read settings
}
}
private static void RestoreUserSettings()
{
if (_initialSettings.Length > 0)
{
File.WriteAllText(_settingsPath, _initialSettings);
}
else
{
File.Delete(_settingsPath);
}
if (_initialZoneSettings.Length > 0)
{
File.WriteAllText(_zoneSettingsPath, _initialZoneSettings);
}
else
{
File.Delete(_zoneSettingsPath);
}
}
}