mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-12-16 03:37:59 +01:00
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:
@@ -1,6 +1,7 @@
|
|||||||
using System.IO;
|
using System.IO;
|
||||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||||
using Newtonsoft.Json.Linq;
|
using Newtonsoft.Json.Linq;
|
||||||
|
using OpenQA.Selenium.Appium.Windows;
|
||||||
using OpenQA.Selenium.Interactions;
|
using OpenQA.Selenium.Interactions;
|
||||||
|
|
||||||
namespace PowerToysTests
|
namespace PowerToysTests
|
||||||
@@ -15,10 +16,11 @@ namespace PowerToysTests
|
|||||||
|
|
||||||
private void CancelTest()
|
private void CancelTest()
|
||||||
{
|
{
|
||||||
new Actions(session).MoveToElement(session.FindElementByXPath("//Button[@Name=\"Cancel\"]")).Click().Perform();
|
WindowsElement cancelButton = session.FindElementByXPath("//Window[@Name=\"FancyZones Editor\"]/Window/Button[@Name=\"Cancel\"]");
|
||||||
|
new Actions(session).MoveToElement(cancelButton).Click().Perform();
|
||||||
ShortWait();
|
ShortWait();
|
||||||
|
|
||||||
Assert.AreEqual(_initialZoneSettings, File.ReadAllText(_zoneSettingsPath), "Settings were changed");
|
Assert.AreEqual(_defaultZoneSettings, File.ReadAllText(_zoneSettingsPath), "Settings were changed");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void SaveTest()
|
private void SaveTest()
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
using System;
|
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Collections.ObjectModel;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
@@ -18,9 +18,10 @@ namespace PowerToysTests
|
|||||||
private JObject _initialSettingsJson;
|
private JObject _initialSettingsJson;
|
||||||
|
|
||||||
private static WindowsElement _saveButton;
|
private static WindowsElement _saveButton;
|
||||||
private static Actions _scrollDown;
|
|
||||||
private static Actions _scrollUp;
|
private static Actions _scrollUp;
|
||||||
|
|
||||||
|
private const int _expectedTogglesCount = 9;
|
||||||
|
|
||||||
private static void Init()
|
private static void Init()
|
||||||
{
|
{
|
||||||
OpenSettings();
|
OpenSettings();
|
||||||
@@ -31,17 +32,12 @@ namespace PowerToysTests
|
|||||||
_saveButton = session.FindElementByName("Save");
|
_saveButton = session.FindElementByName("Save");
|
||||||
Assert.IsNotNull(_saveButton);
|
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()
|
_scrollUp = new Actions(session).MoveToElement(_saveButton).MoveByOffset(0, _saveButton.Rect.Height).ContextClick()
|
||||||
.SendKeys(OpenQA.Selenium.Keys.PageUp + OpenQA.Selenium.Keys.PageUp);
|
.SendKeys(OpenQA.Selenium.Keys.Home);
|
||||||
Assert.IsNotNull(_scrollUp);
|
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 JObject getProperties()
|
private JObject GetProperties()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -54,20 +50,27 @@ namespace PowerToysTests
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private T getPropertyValue<T>(string propertyName)
|
private T GetPropertyValue<T>(string propertyName)
|
||||||
{
|
{
|
||||||
JObject properties = getProperties();
|
JObject properties = GetProperties();
|
||||||
return properties[propertyName].ToObject<JObject>()["value"].Value<T>();
|
return properties[propertyName].ToObject<JObject>()["value"].Value<T>();
|
||||||
}
|
}
|
||||||
|
|
||||||
private T getPropertyValue<T>(JObject properties, string propertyName)
|
private T GetPropertyValue<T>(JObject properties, string propertyName)
|
||||||
{
|
{
|
||||||
return properties[propertyName].ToObject<JObject>()["value"].Value<T>();
|
return properties[propertyName].ToObject<JObject>()["value"].Value<T>();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ScrollDown()
|
private void ScrollDown(int count)
|
||||||
{
|
{
|
||||||
_scrollDown.Perform();
|
Actions scroll = new Actions(session);
|
||||||
|
scroll.MoveToElement(_saveButton).MoveByOffset(0, _saveButton.Rect.Height).ContextClick();
|
||||||
|
for (int i = 0; i < count; i++)
|
||||||
|
{
|
||||||
|
scroll.SendKeys(OpenQA.Selenium.Keys.PageDown);
|
||||||
|
}
|
||||||
|
|
||||||
|
scroll.Perform();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ScrollUp()
|
private void ScrollUp()
|
||||||
@@ -93,7 +96,7 @@ namespace PowerToysTests
|
|||||||
SaveChanges();
|
SaveChanges();
|
||||||
ShortWait();
|
ShortWait();
|
||||||
|
|
||||||
int value = getPropertyValue<int>("fancyzones_highlight_opacity");
|
int value = GetPropertyValue<int>("fancyzones_highlight_opacity");
|
||||||
Assert.AreEqual(expected, value);
|
Assert.AreEqual(expected, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -216,7 +219,7 @@ namespace PowerToysTests
|
|||||||
|
|
||||||
//Assert.AreEqual(expectedText, input.Text);
|
//Assert.AreEqual(expectedText, input.Text);
|
||||||
|
|
||||||
JObject props = getProperties();
|
JObject props = GetProperties();
|
||||||
JObject hotkey = props["fancyzones_editor_hotkey"].ToObject<JObject>()["value"].ToObject<JObject>();
|
JObject hotkey = props["fancyzones_editor_hotkey"].ToObject<JObject>()["value"].ToObject<JObject>();
|
||||||
Assert.AreEqual(flags[0] == 1, hotkey.Value<bool>("win"));
|
Assert.AreEqual(flags[0] == 1, hotkey.Value<bool>("win"));
|
||||||
Assert.AreEqual(flags[1] == 1, hotkey.Value<bool>("ctrl"));
|
Assert.AreEqual(flags[1] == 1, hotkey.Value<bool>("ctrl"));
|
||||||
@@ -225,6 +228,48 @@ namespace PowerToysTests
|
|||||||
//Assert.AreEqual(keyString, hotkey.Value<string>("key"));
|
//Assert.AreEqual(keyString, hotkey.Value<string>("key"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void TestColorSliders(WindowsElement saturationAndBrightness, WindowsElement hue, WindowsElement hex, WindowsElement red, WindowsElement green, WindowsElement blue, string propertyName)
|
||||||
|
{
|
||||||
|
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).Release().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);
|
||||||
|
|
||||||
|
SaveChanges();
|
||||||
|
ShortWait();
|
||||||
|
Assert.AreEqual("#000000", GetPropertyValue<string>(propertyName));
|
||||||
|
|
||||||
|
//white in left corner
|
||||||
|
new Actions(session).MoveToElement(saturationAndBrightness).ClickAndHold().MoveByOffset(-(satRect.Width / 2), -(satRect.Height / 2)).Release().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);
|
||||||
|
|
||||||
|
SaveChanges();
|
||||||
|
ShortWait();
|
||||||
|
Assert.AreEqual("#ffffff", GetPropertyValue<string>(propertyName));
|
||||||
|
|
||||||
|
//color in right corner
|
||||||
|
new Actions(session).MoveToElement(saturationAndBrightness).ClickAndHold().MoveByOffset((satRect.Width / 2), -(satRect.Height / 2)).Release()
|
||||||
|
.MoveToElement(hue).ClickAndHold().MoveByOffset(-(hueRect.Width / 2), 0).Release().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);
|
||||||
|
|
||||||
|
SaveChanges();
|
||||||
|
ShortWait();
|
||||||
|
Assert.AreEqual("#ff0000", GetPropertyValue<string>(propertyName));
|
||||||
|
}
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
public void FancyZonesSettingsOpen()
|
public void FancyZonesSettingsOpen()
|
||||||
{
|
{
|
||||||
@@ -241,7 +286,7 @@ namespace PowerToysTests
|
|||||||
public void TogglesSingleClickSaveButtonTest()
|
public void TogglesSingleClickSaveButtonTest()
|
||||||
{
|
{
|
||||||
List<WindowsElement> toggles = session.FindElementsByXPath("//Pane[@Name=\"PowerToys Settings\"]/*[@LocalizedControlType=\"toggleswitch\"]").ToList();
|
List<WindowsElement> toggles = session.FindElementsByXPath("//Pane[@Name=\"PowerToys Settings\"]/*[@LocalizedControlType=\"toggleswitch\"]").ToList();
|
||||||
Assert.AreEqual(8, toggles.Count);
|
Assert.AreEqual(_expectedTogglesCount, toggles.Count);
|
||||||
|
|
||||||
List<bool> toggleValues = new List<bool>();
|
List<bool> toggleValues = new List<bool>();
|
||||||
foreach (WindowsElement toggle in toggles)
|
foreach (WindowsElement toggle in toggles)
|
||||||
@@ -258,15 +303,16 @@ namespace PowerToysTests
|
|||||||
}
|
}
|
||||||
|
|
||||||
//check saved settings
|
//check saved settings
|
||||||
JObject savedProps = getProperties();
|
JObject savedProps = GetProperties();
|
||||||
Assert.AreNotEqual(toggleValues[0], getPropertyValue<bool>(savedProps, "fancyzones_shiftDrag"));
|
Assert.AreNotEqual(toggleValues[0], GetPropertyValue<bool>(savedProps, "fancyzones_shiftDrag"));
|
||||||
Assert.AreNotEqual(toggleValues[1], getPropertyValue<bool>(savedProps, "fancyzones_overrideSnapHotkeys"));
|
Assert.AreNotEqual(toggleValues[1], GetPropertyValue<bool>(savedProps, "fancyzones_overrideSnapHotkeys"));
|
||||||
Assert.AreNotEqual(toggleValues[2], getPropertyValue<bool>(savedProps, "fancyzones_zoneSetChange_flashZones"));
|
Assert.AreNotEqual(toggleValues[2], GetPropertyValue<bool>(savedProps, "fancyzones_displayChange_moveWindows"));
|
||||||
Assert.AreNotEqual(toggleValues[3], getPropertyValue<bool>(savedProps, "fancyzones_displayChange_moveWindows"));
|
Assert.AreNotEqual(toggleValues[3], GetPropertyValue<bool>(savedProps, "fancyzones_zoneSetChange_moveWindows"));
|
||||||
Assert.AreNotEqual(toggleValues[4], getPropertyValue<bool>(savedProps, "fancyzones_zoneSetChange_moveWindows"));
|
Assert.AreNotEqual(toggleValues[4], GetPropertyValue<bool>(savedProps, "fancyzones_virtualDesktopChange_moveWindows"));
|
||||||
Assert.AreNotEqual(toggleValues[5], getPropertyValue<bool>(savedProps, "fancyzones_virtualDesktopChange_moveWindows"));
|
Assert.AreNotEqual(toggleValues[5], GetPropertyValue<bool>(savedProps, "fancyzones_appLastZone_moveWindows"));
|
||||||
Assert.AreNotEqual(toggleValues[6], getPropertyValue<bool>(savedProps, "fancyzones_appLastZone_moveWindows"));
|
Assert.AreNotEqual(toggleValues[6], GetPropertyValue<bool>(savedProps, "use_cursorpos_editor_startupscreen"));
|
||||||
Assert.AreNotEqual(toggleValues[7], getPropertyValue<bool>(savedProps, "use_cursorpos_editor_startupscreen"));
|
Assert.AreNotEqual(toggleValues[7], GetPropertyValue<bool>(savedProps, "fancyzones_show_on_all_monitors"));
|
||||||
|
Assert.AreNotEqual(toggleValues[8], GetPropertyValue<bool>(savedProps, "fancyzones_makeDraggedWindowTransparent"));
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -278,7 +324,7 @@ namespace PowerToysTests
|
|||||||
public void TogglesDoubleClickSave()
|
public void TogglesDoubleClickSave()
|
||||||
{
|
{
|
||||||
List<WindowsElement> toggles = session.FindElementsByXPath("//Pane[@Name=\"PowerToys Settings\"]/*[@LocalizedControlType=\"toggleswitch\"]").ToList();
|
List<WindowsElement> toggles = session.FindElementsByXPath("//Pane[@Name=\"PowerToys Settings\"]/*[@LocalizedControlType=\"toggleswitch\"]").ToList();
|
||||||
Assert.AreEqual(8, toggles.Count);
|
Assert.AreEqual(_expectedTogglesCount, toggles.Count);
|
||||||
|
|
||||||
List<bool> toggleValues = new List<bool>();
|
List<bool> toggleValues = new List<bool>();
|
||||||
foreach (WindowsElement toggle in toggles)
|
foreach (WindowsElement toggle in toggles)
|
||||||
@@ -295,21 +341,22 @@ namespace PowerToysTests
|
|||||||
SaveChanges();
|
SaveChanges();
|
||||||
ShortWait();
|
ShortWait();
|
||||||
|
|
||||||
JObject savedProps = getProperties();
|
JObject savedProps = GetProperties();
|
||||||
Assert.AreEqual(toggleValues[0], getPropertyValue<bool>(savedProps, "fancyzones_shiftDrag"));
|
Assert.AreEqual(toggleValues[0], GetPropertyValue<bool>(savedProps, "fancyzones_shiftDrag"));
|
||||||
Assert.AreEqual(toggleValues[1], getPropertyValue<bool>(savedProps, "fancyzones_overrideSnapHotkeys"));
|
Assert.AreEqual(toggleValues[1], GetPropertyValue<bool>(savedProps, "fancyzones_overrideSnapHotkeys"));
|
||||||
Assert.AreEqual(toggleValues[2], getPropertyValue<bool>(savedProps, "fancyzones_zoneSetChange_flashZones"));
|
Assert.AreEqual(toggleValues[2], GetPropertyValue<bool>(savedProps, "fancyzones_displayChange_moveWindows"));
|
||||||
Assert.AreEqual(toggleValues[3], getPropertyValue<bool>(savedProps, "fancyzones_displayChange_moveWindows"));
|
Assert.AreEqual(toggleValues[3], GetPropertyValue<bool>(savedProps, "fancyzones_zoneSetChange_moveWindows"));
|
||||||
Assert.AreEqual(toggleValues[4], getPropertyValue<bool>(savedProps, "fancyzones_zoneSetChange_moveWindows"));
|
Assert.AreEqual(toggleValues[4], GetPropertyValue<bool>(savedProps, "fancyzones_virtualDesktopChange_moveWindows"));
|
||||||
Assert.AreEqual(toggleValues[5], getPropertyValue<bool>(savedProps, "fancyzones_virtualDesktopChange_moveWindows"));
|
Assert.AreEqual(toggleValues[5], GetPropertyValue<bool>(savedProps, "fancyzones_appLastZone_moveWindows"));
|
||||||
Assert.AreEqual(toggleValues[6], getPropertyValue<bool>(savedProps, "fancyzones_appLastZone_moveWindows"));
|
Assert.AreEqual(toggleValues[6], GetPropertyValue<bool>(savedProps, "use_cursorpos_editor_startupscreen"));
|
||||||
Assert.AreEqual(toggleValues[7], getPropertyValue<bool>(savedProps, "use_cursorpos_editor_startupscreen"));
|
Assert.AreEqual(toggleValues[7], GetPropertyValue<bool>(savedProps, "fancyzones_show_on_all_monitors"));
|
||||||
|
Assert.AreEqual(toggleValues[8], GetPropertyValue<bool>(savedProps, "fancyzones_makeDraggedWindowTransparent"));
|
||||||
}
|
}
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
public void HighlightOpacitySetValue()
|
public void HighlightOpacitySetValue()
|
||||||
{
|
{
|
||||||
WindowsElement editor = session.FindElementByName("Zone Highlight Opacity (%)");
|
WindowsElement editor = session.FindElementByName("Zone opacity (%)");
|
||||||
Assert.IsNotNull(editor);
|
Assert.IsNotNull(editor);
|
||||||
|
|
||||||
SetOpacity(editor, "50");
|
SetOpacity(editor, "50");
|
||||||
@@ -339,7 +386,7 @@ namespace PowerToysTests
|
|||||||
[TestMethod]
|
[TestMethod]
|
||||||
public void HighlightOpacityIncreaseValue()
|
public void HighlightOpacityIncreaseValue()
|
||||||
{
|
{
|
||||||
WindowsElement editor = session.FindElementByName("Zone Highlight Opacity (%)");
|
WindowsElement editor = session.FindElementByName("Zone opacity (%)");
|
||||||
Assert.IsNotNull(editor);
|
Assert.IsNotNull(editor);
|
||||||
|
|
||||||
SetOpacity(editor, "99");
|
SetOpacity(editor, "99");
|
||||||
@@ -364,7 +411,7 @@ namespace PowerToysTests
|
|||||||
public void HighlightOpacityDecreaseValue()
|
public void HighlightOpacityDecreaseValue()
|
||||||
{
|
{
|
||||||
|
|
||||||
WindowsElement editor = session.FindElementByName("Zone Highlight Opacity (%)");
|
WindowsElement editor = session.FindElementByName("Zone opacity (%)");
|
||||||
Assert.IsNotNull(editor);
|
Assert.IsNotNull(editor);
|
||||||
|
|
||||||
SetOpacity(editor, "1");
|
SetOpacity(editor, "1");
|
||||||
@@ -388,7 +435,8 @@ namespace PowerToysTests
|
|||||||
[TestMethod]
|
[TestMethod]
|
||||||
public void HighlightOpacityClearValueButton()
|
public void HighlightOpacityClearValueButton()
|
||||||
{
|
{
|
||||||
WindowsElement editor = session.FindElementByName("Zone Highlight Opacity (%)");
|
ScrollDown(3);
|
||||||
|
WindowsElement editor = session.FindElementByName("Zone opacity (%)");
|
||||||
Assert.IsNotNull(editor);
|
Assert.IsNotNull(editor);
|
||||||
|
|
||||||
editor.Click(); //activate
|
editor.Click(); //activate
|
||||||
@@ -402,71 +450,33 @@ namespace PowerToysTests
|
|||||||
Assert.AreEqual("\r\n", editor.Text);
|
Assert.AreEqual("\r\n", editor.Text);
|
||||||
}
|
}
|
||||||
|
|
||||||
//in 0.15.2 sliders cannot be found by inspect.exe
|
|
||||||
/*
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
public void HighlightColorSlidersTest()
|
public void HighlightColorSlidersTest()
|
||||||
{
|
{
|
||||||
ScrollDown();
|
ScrollDown(4);
|
||||||
|
|
||||||
WindowsElement saturationAndBrightness = session.FindElementByName("Saturation and brightness");
|
ReadOnlyCollection<WindowsElement> saturationAndBrightness = session.FindElementsByName("Saturation and brightness");
|
||||||
WindowsElement hue = session.FindElementByName("Hue");
|
ReadOnlyCollection<WindowsElement> hue = session.FindElementsByName("Hue");
|
||||||
WindowsElement hex = session.FindElementByXPath("//Edit[@Name=\"Hex\"]");
|
ReadOnlyCollection<WindowsElement> hex = session.FindElementsByXPath("//Edit[@Name=\"Hex\"]");
|
||||||
WindowsElement red = session.FindElementByXPath("//Edit[@Name=\"Red\"]");
|
ReadOnlyCollection<WindowsElement> red = session.FindElementsByXPath("//Edit[@Name=\"Red\"]");
|
||||||
WindowsElement green = session.FindElementByXPath("//Edit[@Name=\"Green\"]");
|
ReadOnlyCollection<WindowsElement> green = session.FindElementsByXPath("//Edit[@Name=\"Green\"]");
|
||||||
WindowsElement blue = session.FindElementByXPath("//Edit[@Name=\"Blue\"]");
|
ReadOnlyCollection<WindowsElement> blue = session.FindElementsByXPath("//Edit[@Name=\"Blue\"]");
|
||||||
|
|
||||||
Assert.IsNotNull(saturationAndBrightness);
|
TestColorSliders(saturationAndBrightness[2], hue[2], hex[2], red[2], green[2], blue[2], "fancyzones_zoneBorderColor");
|
||||||
Assert.IsNotNull(hue);
|
|
||||||
Assert.IsNotNull(hex);
|
|
||||||
Assert.IsNotNull(red);
|
|
||||||
Assert.IsNotNull(green);
|
|
||||||
Assert.IsNotNull(blue);
|
|
||||||
|
|
||||||
System.Drawing.Rectangle satRect = saturationAndBrightness.Rect;
|
new Actions(session).MoveToElement(saturationAndBrightness[2]).MoveByOffset(saturationAndBrightness[2].Rect.Width / 2 + 10, 0)
|
||||||
System.Drawing.Rectangle hueRect = hue.Rect;
|
.Click().SendKeys(OpenQA.Selenium.Keys.PageUp).Perform();
|
||||||
|
TestColorSliders(saturationAndBrightness[1], hue[1], hex[1], red[1], green[1], blue[1], "fancyzones_zoneColor");
|
||||||
|
|
||||||
//black on the bottom
|
new Actions(session).MoveToElement(saturationAndBrightness[1]).MoveByOffset(saturationAndBrightness[1].Rect.Width / 2 + 10, 0)
|
||||||
new Actions(session).MoveToElement(saturationAndBrightness).ClickAndHold().MoveByOffset(0, satRect.Height / 2).Click().Perform();
|
.Click().SendKeys(OpenQA.Selenium.Keys.PageDown + OpenQA.Selenium.Keys.PageDown).SendKeys(OpenQA.Selenium.Keys.PageUp + OpenQA.Selenium.Keys.PageUp).Perform();
|
||||||
ShortWait();
|
TestColorSliders(saturationAndBrightness[0], hue[0], hex[0], red[0], green[0], blue[0], "fancyzones_zoneHighlightColor");
|
||||||
|
|
||||||
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);
|
|
||||||
|
|
||||||
SaveChanges();
|
|
||||||
ShortWait();
|
|
||||||
Assert.AreEqual("#000000", getPropertyValue<string>("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);
|
|
||||||
|
|
||||||
SaveChanges();
|
|
||||||
ShortWait();
|
|
||||||
Assert.AreEqual("#ffffff", getPropertyValue<string>("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);
|
|
||||||
|
|
||||||
SaveChanges();
|
|
||||||
ShortWait();
|
|
||||||
Assert.AreEqual("#ff0000", getPropertyValue<string>("fancyzones_zoneHighlightColor"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
public void HighlightColorTest()
|
public void HighlightColorTest()
|
||||||
{
|
{
|
||||||
ScrollDown();
|
ScrollDown(2);
|
||||||
|
|
||||||
WindowsElement saturationAndBrightness = session.FindElementByName("Saturation and brightness");
|
WindowsElement saturationAndBrightness = session.FindElementByName("Saturation and brightness");
|
||||||
WindowsElement hue = session.FindElementByName("Hue");
|
WindowsElement hue = session.FindElementByName("Hue");
|
||||||
@@ -485,14 +495,13 @@ namespace PowerToysTests
|
|||||||
|
|
||||||
SaveChanges();
|
SaveChanges();
|
||||||
ShortWait();
|
ShortWait();
|
||||||
Assert.AreEqual("#63c99a", getPropertyValue<string>("fancyzones_zoneHighlightColor"));
|
Assert.AreEqual("#63c99a", GetPropertyValue<string>("fancyzones_zoneHighlightColor"));
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
public void HighlightRGBInputsTest()
|
public void HighlightRGBInputsTest()
|
||||||
{
|
{
|
||||||
ScrollDown();
|
ScrollDown(2);
|
||||||
|
|
||||||
TestRgbInput("Red");
|
TestRgbInput("Red");
|
||||||
TestRgbInput("Green");
|
TestRgbInput("Green");
|
||||||
@@ -502,7 +511,7 @@ namespace PowerToysTests
|
|||||||
[TestMethod]
|
[TestMethod]
|
||||||
public void HighlightHexInputTest()
|
public void HighlightHexInputTest()
|
||||||
{
|
{
|
||||||
ScrollDown();
|
ScrollDown(2);
|
||||||
|
|
||||||
WindowsElement hexInput = session.FindElementByXPath("//Edit[@Name=\"Hex\"]");
|
WindowsElement hexInput = session.FindElementByXPath("//Edit[@Name=\"Hex\"]");
|
||||||
Assert.IsNotNull(hexInput);
|
Assert.IsNotNull(hexInput);
|
||||||
@@ -557,7 +566,7 @@ namespace PowerToysTests
|
|||||||
SaveChanges();
|
SaveChanges();
|
||||||
ClearInput(input);
|
ClearInput(input);
|
||||||
ShortWait();
|
ShortWait();
|
||||||
Assert.AreEqual(inputValue, getPropertyValue<string>("fancyzones_excluded_apps"));
|
Assert.AreEqual(inputValue, GetPropertyValue<string>("fancyzones_excluded_apps"));
|
||||||
|
|
||||||
//invalid
|
//invalid
|
||||||
inputValue = "Notepad Chrome";
|
inputValue = "Notepad Chrome";
|
||||||
@@ -565,28 +574,28 @@ namespace PowerToysTests
|
|||||||
SaveChanges();
|
SaveChanges();
|
||||||
ClearInput(input);
|
ClearInput(input);
|
||||||
ShortWait();
|
ShortWait();
|
||||||
Assert.AreEqual(inputValue, getPropertyValue<string>("fancyzones_excluded_apps"));
|
Assert.AreEqual(inputValue, GetPropertyValue<string>("fancyzones_excluded_apps"));
|
||||||
|
|
||||||
inputValue = "Notepad,Chrome";
|
inputValue = "Notepad,Chrome";
|
||||||
input.SendKeys(inputValue);
|
input.SendKeys(inputValue);
|
||||||
SaveChanges();
|
SaveChanges();
|
||||||
ClearInput(input);
|
ClearInput(input);
|
||||||
ShortWait();
|
ShortWait();
|
||||||
Assert.AreEqual(inputValue, getPropertyValue<string>("fancyzones_excluded_apps"));
|
Assert.AreEqual(inputValue, GetPropertyValue<string>("fancyzones_excluded_apps"));
|
||||||
|
|
||||||
inputValue = "Note*";
|
inputValue = "Note*";
|
||||||
input.SendKeys(inputValue);
|
input.SendKeys(inputValue);
|
||||||
SaveChanges();
|
SaveChanges();
|
||||||
ClearInput(input);
|
ClearInput(input);
|
||||||
ShortWait();
|
ShortWait();
|
||||||
Assert.AreEqual(inputValue, getPropertyValue<string>("fancyzones_excluded_apps"));
|
Assert.AreEqual(inputValue, GetPropertyValue<string>("fancyzones_excluded_apps"));
|
||||||
|
|
||||||
inputValue = "Кириллица";
|
inputValue = "Кириллица";
|
||||||
input.SendKeys(inputValue);
|
input.SendKeys(inputValue);
|
||||||
SaveChanges();
|
SaveChanges();
|
||||||
ClearInput(input);
|
ClearInput(input);
|
||||||
ShortWait();
|
ShortWait();
|
||||||
Assert.AreEqual(inputValue, getPropertyValue<string>("fancyzones_excluded_apps"));
|
Assert.AreEqual(inputValue, GetPropertyValue<string>("fancyzones_excluded_apps"));
|
||||||
}
|
}
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
@@ -609,9 +618,9 @@ namespace PowerToysTests
|
|||||||
Assert.IsNotNull(powerToysWindow);
|
Assert.IsNotNull(powerToysWindow);
|
||||||
|
|
||||||
//check settings change
|
//check settings change
|
||||||
JObject savedProps = getProperties();
|
JObject savedProps = GetProperties();
|
||||||
|
|
||||||
Assert.AreNotEqual(initialToggleValue, getPropertyValue<bool>(savedProps, "fancyzones_shiftDrag"));
|
Assert.AreNotEqual(initialToggleValue, GetPropertyValue<bool>(savedProps, "fancyzones_shiftDrag"));
|
||||||
|
|
||||||
//return initial app state
|
//return initial app state
|
||||||
toggle.Click();
|
toggle.Click();
|
||||||
@@ -648,8 +657,8 @@ namespace PowerToysTests
|
|||||||
Init();
|
Init();
|
||||||
|
|
||||||
//check settings change
|
//check settings change
|
||||||
JObject savedProps = getProperties();
|
JObject savedProps = GetProperties();
|
||||||
Assert.AreEqual(initialToggleValue, getPropertyValue<bool>(savedProps, "fancyzones_shiftDrag"));
|
Assert.AreEqual(initialToggleValue, GetPropertyValue<bool>(savedProps, "fancyzones_shiftDrag"));
|
||||||
}
|
}
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
@@ -670,9 +679,9 @@ namespace PowerToysTests
|
|||||||
Assert.IsNotNull(powerToysWindow);
|
Assert.IsNotNull(powerToysWindow);
|
||||||
|
|
||||||
//check settings change
|
//check settings change
|
||||||
JObject savedProps = getProperties();
|
JObject savedProps = GetProperties();
|
||||||
JObject initialProps = _initialSettingsJson["properties"].ToObject<JObject>();
|
JObject initialProps = _initialSettingsJson["properties"].ToObject<JObject>();
|
||||||
Assert.AreEqual(getPropertyValue<bool>(initialProps, "fancyzones_shiftDrag"), getPropertyValue<bool>(savedProps, "fancyzones_shiftDrag"));
|
Assert.AreEqual(GetPropertyValue<bool>(initialProps, "fancyzones_shiftDrag"), GetPropertyValue<bool>(savedProps, "fancyzones_shiftDrag"));
|
||||||
|
|
||||||
//return initial app state
|
//return initial app state
|
||||||
toggle.Click();
|
toggle.Click();
|
||||||
|
|||||||
@@ -17,28 +17,20 @@ namespace PowerToysTests
|
|||||||
protected static bool isPowerToysLaunched = false;
|
protected static bool isPowerToysLaunched = false;
|
||||||
protected static WindowsElement trayButton;
|
protected static WindowsElement trayButton;
|
||||||
|
|
||||||
protected static string _settingsFolderPath = "";
|
protected static string _settingsFolderPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Microsoft\\PowerToys\\FancyZones");
|
||||||
protected static string _settingsPath = "";
|
protected static string _settingsPath = _settingsFolderPath + "\\settings.json";
|
||||||
protected static string _zoneSettingsPath = "";
|
protected static string _zoneSettingsPath = _settingsFolderPath + "\\zones-settings.json";
|
||||||
|
|
||||||
protected static string _initialSettings = "";
|
protected static string _initialSettings = "";
|
||||||
protected static string _initialZoneSettings = "";
|
protected static string _initialZoneSettings = "";
|
||||||
|
|
||||||
|
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)
|
public static void Setup(TestContext context, bool isLaunchRequired = true)
|
||||||
{
|
{
|
||||||
//read settings before running tests to restore them after
|
ReadUserSettings(); //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
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if (session == null)
|
if (session == null)
|
||||||
{
|
{
|
||||||
@@ -57,29 +49,11 @@ namespace PowerToysTests
|
|||||||
LaunchPowerToys();
|
LaunchPowerToys();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void TearDown()
|
public static void TearDown()
|
||||||
{
|
{
|
||||||
//restore initial settings files
|
RestoreUserSettings(); //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);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (session != null)
|
if (session != null)
|
||||||
{
|
{
|
||||||
@@ -201,7 +175,9 @@ namespace PowerToysTests
|
|||||||
{
|
{
|
||||||
AppiumOptions opts = new AppiumOptions();
|
AppiumOptions opts = new AppiumOptions();
|
||||||
opts.PlatformName = "Windows";
|
opts.PlatformName = "Windows";
|
||||||
opts.AddAdditionalCapability("app", "Microsoft.PowerToys_8wekyb3d8bbwe!PowerToys");
|
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);
|
WindowsDriver<WindowsElement> driver = new WindowsDriver<WindowsElement>(new Uri(WindowsApplicationDriverUrl), opts);
|
||||||
Assert.IsNotNull(driver);
|
Assert.IsNotNull(driver);
|
||||||
@@ -232,38 +208,73 @@ namespace PowerToysTests
|
|||||||
|
|
||||||
public static void ResetDefaultFancyZonesSettings(bool relaunch)
|
public static void ResetDefaultFancyZonesSettings(bool relaunch)
|
||||||
{
|
{
|
||||||
if (!Directory.Exists(_settingsFolderPath))
|
ResetSettings(_settingsFolderPath, _settingsPath, _defaultSettings, relaunch);
|
||||||
{
|
|
||||||
Directory.CreateDirectory(_settingsFolderPath);
|
|
||||||
}
|
|
||||||
|
|
||||||
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);
|
|
||||||
|
|
||||||
if (isPowerToysLaunched)
|
|
||||||
{
|
|
||||||
ExitPowerToys();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (relaunch)
|
|
||||||
{
|
|
||||||
LaunchPowerToys();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void ResetDefautZoneSettings(bool relaunch)
|
public static void ResetDefautZoneSettings(bool relaunch)
|
||||||
{
|
{
|
||||||
string zoneSettings = "{\"app-zone-history\":[],\"devices\":[],\"custom-zone-sets\":[]}";
|
ResetSettings(_settingsFolderPath, _zoneSettingsPath, _defaultZoneSettings, relaunch);
|
||||||
File.WriteAllText(_zoneSettingsPath, zoneSettings);
|
}
|
||||||
|
|
||||||
|
private static void ResetSettings(string folder, string filePath, string data, bool relaunch)
|
||||||
|
{
|
||||||
|
if (!Directory.Exists(folder))
|
||||||
|
{
|
||||||
|
Directory.CreateDirectory(folder);
|
||||||
|
}
|
||||||
|
File.WriteAllText(filePath, data);
|
||||||
|
|
||||||
if (isPowerToysLaunched)
|
if (isPowerToysLaunched)
|
||||||
{
|
{
|
||||||
ExitPowerToys();
|
ExitPowerToys();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (relaunch)
|
if (relaunch)
|
||||||
{
|
{
|
||||||
LaunchPowerToys();
|
LaunchPowerToys();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void ReadUserSettings()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_initialSettings = File.ReadAllText(_settingsPath);
|
||||||
|
}
|
||||||
|
catch (Exception)
|
||||||
|
{
|
||||||
|
//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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||||
|
using OpenQA.Selenium.Appium;
|
||||||
using OpenQA.Selenium.Appium.Windows;
|
using OpenQA.Selenium.Appium.Windows;
|
||||||
using OpenQA.Selenium.Interactions;
|
using OpenQA.Selenium.Interactions;
|
||||||
|
|
||||||
@@ -55,10 +56,12 @@ namespace PowerToysTests
|
|||||||
trayButton.Click();
|
trayButton.Click();
|
||||||
isTrayOpened = true;
|
isTrayOpened = true;
|
||||||
|
|
||||||
WindowsElement pt = session.FindElementByName("PowerToys");
|
WindowsElement notificationOverflow = session.FindElementByName("Notification Overflow");
|
||||||
Assert.IsNotNull(pt);
|
AppiumWebElement overflowArea = notificationOverflow.FindElementByName("Overflow Notification Area");
|
||||||
|
AppiumWebElement powerToys = overflowArea.FindElementByName("PowerToys");
|
||||||
|
Assert.IsNotNull(powerToys);
|
||||||
|
|
||||||
new Actions(session).MoveToElement(pt).ContextClick().Perform();
|
new Actions(session).MoveToElement(powerToys).ContextClick().Perform();
|
||||||
ShortWait();
|
ShortWait();
|
||||||
|
|
||||||
//exit
|
//exit
|
||||||
@@ -66,10 +69,12 @@ namespace PowerToysTests
|
|||||||
ShortWait();
|
ShortWait();
|
||||||
|
|
||||||
//check PowerToys exited
|
//check PowerToys exited
|
||||||
pt = null;
|
powerToys = null;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
pt = session.FindElementByName("PowerToys");
|
notificationOverflow = session.FindElementByName("Notification Overflow");
|
||||||
|
overflowArea = notificationOverflow.FindElementByName("Overflow Notification Area");
|
||||||
|
powerToys = overflowArea.FindElementByName("PowerToys");
|
||||||
}
|
}
|
||||||
catch (OpenQA.Selenium.WebDriverException)
|
catch (OpenQA.Selenium.WebDriverException)
|
||||||
{
|
{
|
||||||
@@ -79,7 +84,7 @@ namespace PowerToysTests
|
|||||||
LaunchPowerToys();
|
LaunchPowerToys();
|
||||||
ShortWait();
|
ShortWait();
|
||||||
|
|
||||||
Assert.IsNull(pt);
|
Assert.IsNull(powerToys);
|
||||||
}
|
}
|
||||||
|
|
||||||
[ClassInitialize]
|
[ClassInitialize]
|
||||||
|
|||||||
Reference in New Issue
Block a user