Editor custom layouts tests (#1757)

This commit is contained in:
Seraphima Zykova 2020-03-31 15:15:51 +03:00 committed by GitHub
parent 5661be3ebd
commit e122217101
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 1125 additions and 118 deletions

View File

@ -0,0 +1,315 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenQA.Selenium.Appium.Windows;
using OpenQA.Selenium.Interactions;
using System.Windows.Forms;
namespace PowerToysTests
{
[TestClass]
public class FancyZonesEditorCanvasZoneResizeTests : FancyZonesEditor
{
private void MoveCorner(WindowsElement corner, bool shiftLeft, bool shiftUp, int xOffset, int yOffset)
{
int shiftX = shiftLeft ? -(corner.Rect.Width / 2) + 1 : (corner.Rect.Width / 2) - 1;
int shiftY = shiftUp ? -(corner.Rect.Height / 2) + 1 : (corner.Rect.Height / 2) - 1;
new Actions(session).MoveToElement(corner)
.MoveByOffset(shiftX, shiftY)
.ClickAndHold().MoveByOffset(xOffset, yOffset).Release().Perform();
}
[TestMethod]
public void MoveTopBorder()
{
WindowsElement topBorder = session.FindElementByAccessibilityId("NResize");
WindowsElement bottomBorder = session.FindElementByAccessibilityId("SResize");
Assert.IsNotNull(topBorder);
Assert.IsNotNull(bottomBorder);
//up
new Actions(session).MoveToElement(topBorder).ClickAndHold().MoveByOffset(0, -5000).Release().Perform();
Assert.IsTrue(topBorder.Rect.Y >= 0);
//down
new Actions(session).MoveToElement(topBorder).ClickAndHold().MoveByOffset(0, 5000).Release().Perform();
Assert.IsTrue(topBorder.Rect.Y <= bottomBorder.Rect.Y);
}
[TestMethod]
public void MoveBottomBorder()
{
WindowsElement topBorder = session.FindElementByAccessibilityId("NResize");
WindowsElement bottomBorder = session.FindElementByAccessibilityId("SResize");
Assert.IsNotNull(topBorder);
Assert.IsNotNull(bottomBorder);
//up
new Actions(session).MoveToElement(bottomBorder).ClickAndHold().MoveByOffset(0, -5000).Release().Perform();
Assert.IsTrue(topBorder.Rect.Y <= bottomBorder.Rect.Y);
//down
new Actions(session).MoveToElement(bottomBorder).ClickAndHold().MoveByOffset(0, 5000).Release().Perform();
Assert.IsTrue(bottomBorder.Rect.Y <= Screen.PrimaryScreen.WorkingArea.Bottom);
}
[TestMethod]
public void MoveLeftBorder()
{
WindowsElement leftBorder = session.FindElementByAccessibilityId("WResize");
WindowsElement rightBorder = session.FindElementByAccessibilityId("EResize");
Assert.IsNotNull(leftBorder);
Assert.IsNotNull(rightBorder);
//to the left
new Actions(session).MoveToElement(leftBorder).ClickAndHold().MoveByOffset(-5000, 0).Release().Perform();
Assert.IsTrue(leftBorder.Rect.Y <= Screen.PrimaryScreen.WorkingArea.Bottom);
//to the right
new Actions(session).MoveToElement(leftBorder).ClickAndHold().MoveByOffset(5000, 0).Release().Perform();
Assert.IsTrue(leftBorder.Rect.X <= rightBorder.Rect.X);
}
[TestMethod]
public void MoveRightBorder()
{
WindowsElement leftBorder = session.FindElementByAccessibilityId("WResize");
WindowsElement rightBorder = session.FindElementByAccessibilityId("EResize");
Assert.IsNotNull(leftBorder);
Assert.IsNotNull(rightBorder);
//to the left
new Actions(session).MoveToElement(rightBorder).ClickAndHold().MoveByOffset(-5000, 0).Release().Perform();
Assert.IsTrue(leftBorder.Rect.X <= rightBorder.Rect.X);
//to the right
new Actions(session).MoveToElement(rightBorder).ClickAndHold().MoveByOffset(5000, 0).Release().Perform();
Assert.IsTrue(leftBorder.Rect.X <= Screen.PrimaryScreen.WorkingArea.Right);
}
[TestMethod]
public void MoveTopLeftCorner()
{
WindowsElement topLeftCorner = session.FindElementByAccessibilityId("NWResize");
WindowsElement bottomBorder = session.FindElementByAccessibilityId("SResize");
WindowsElement rightBorder = session.FindElementByAccessibilityId("EResize");
Assert.IsNotNull(topLeftCorner);
Assert.IsNotNull(bottomBorder);
Assert.IsNotNull(rightBorder);
//up
MoveCorner(topLeftCorner, true, true, 0, -5000);
Assert.IsTrue(topLeftCorner.Rect.Y >= 0);
//down
MoveCorner(topLeftCorner, true, true, 0, 5000);
Assert.IsTrue(topLeftCorner.Rect.Y <= bottomBorder.Rect.Y);
//up-left
MoveCorner(topLeftCorner, true, true, -5000, -5000);
Assert.IsTrue(topLeftCorner.Rect.Y >= 0);
Assert.IsTrue(topLeftCorner.Rect.X >= 0);
//up-right
MoveCorner(topLeftCorner, true, true, 5000, -5000);
Assert.IsTrue(topLeftCorner.Rect.Y >= 0);
Assert.IsTrue(topLeftCorner.Rect.X <= rightBorder.Rect.X);
//to the left
MoveCorner(topLeftCorner, true, true, -5000, 0);
Assert.IsTrue(topLeftCorner.Rect.X >= 0);
//to the right
MoveCorner(topLeftCorner, true, true, 5000, 0);
Assert.IsTrue(topLeftCorner.Rect.X <= rightBorder.Rect.X);
//down-left
MoveCorner(topLeftCorner, true, true, -5000, 5000);
Assert.IsTrue(topLeftCorner.Rect.Y <= bottomBorder.Rect.Y);
Assert.IsTrue(topLeftCorner.Rect.X >= 0);
//down-right
MoveCorner(topLeftCorner, true, true, 5000, 5000);
Assert.IsTrue(topLeftCorner.Rect.Y <= bottomBorder.Rect.Y);
Assert.IsTrue(topLeftCorner.Rect.X <= rightBorder.Rect.X);
}
[TestMethod]
public void MoveTopRightCorner()
{
WindowsElement topRightCorner = session.FindElementByAccessibilityId("NEResize");
WindowsElement bottomBorder = session.FindElementByAccessibilityId("SResize");
WindowsElement leftBorder = session.FindElementByAccessibilityId("WResize");
Assert.IsNotNull(topRightCorner);
Assert.IsNotNull(bottomBorder);
Assert.IsNotNull(leftBorder);
//up
MoveCorner(topRightCorner, false, true, 0, -5000);
Assert.IsTrue(topRightCorner.Rect.Y >= 0);
//down
MoveCorner(topRightCorner, false, true, 0, 5000);
Assert.IsTrue(topRightCorner.Rect.Y <= bottomBorder.Rect.Y);
//up-left
MoveCorner(topRightCorner, false, true, -5000, -5000);
Assert.IsTrue(topRightCorner.Rect.Y >= 0);
Assert.IsTrue(topRightCorner.Rect.X >= leftBorder.Rect.X);
//up-right
MoveCorner(topRightCorner, false, true, 5000, -5000);
Assert.IsTrue(topRightCorner.Rect.Y >= 0);
Assert.IsTrue(leftBorder.Rect.X <= Screen.PrimaryScreen.WorkingArea.Right);
//to the left
MoveCorner(topRightCorner, false, true, -5000, 0);
Assert.IsTrue(topRightCorner.Rect.X >= leftBorder.Rect.X);
//to the right
MoveCorner(topRightCorner, false, true, 5000, 0);
Assert.IsTrue(leftBorder.Rect.X <= Screen.PrimaryScreen.WorkingArea.Right);
//down-right
MoveCorner(topRightCorner, false, true, 5000, 5000);
Assert.IsTrue(topRightCorner.Rect.Y <= bottomBorder.Rect.Y);
Assert.IsTrue(leftBorder.Rect.X <= Screen.PrimaryScreen.WorkingArea.Right);
//down-left
MoveCorner(topRightCorner, false, true, -5000, 5000);
Assert.IsTrue(topRightCorner.Rect.Y <= bottomBorder.Rect.Y);
Assert.IsTrue(topRightCorner.Rect.X >= leftBorder.Rect.X);
}
[TestMethod]
public void MoveBottomLeftCorner()
{
WindowsElement bottomLeftCorner = session.FindElementByAccessibilityId("SWResize");
WindowsElement topBorder = session.FindElementByAccessibilityId("NResize");
WindowsElement rightBorder = session.FindElementByAccessibilityId("EResize");
Assert.IsNotNull(bottomLeftCorner);
Assert.IsNotNull(topBorder);
Assert.IsNotNull(rightBorder);
//down
MoveCorner(bottomLeftCorner, true, false, 0, 5000);
Assert.IsTrue(bottomLeftCorner.Rect.Y <= Screen.PrimaryScreen.WorkingArea.Bottom);
//up
MoveCorner(bottomLeftCorner, true, false, 0, -5000);
Assert.IsTrue(bottomLeftCorner.Rect.Y >= topBorder.Rect.Y);
//down-right
MoveCorner(bottomLeftCorner, true, false, 5000, 5000);
Assert.IsTrue(bottomLeftCorner.Rect.Y <= Screen.PrimaryScreen.WorkingArea.Bottom);
Assert.IsTrue(bottomLeftCorner.Rect.X <= rightBorder.Rect.X);
//down-left
MoveCorner(bottomLeftCorner, true, false, -5000, 5000);
Assert.IsTrue(bottomLeftCorner.Rect.Y <= Screen.PrimaryScreen.WorkingArea.Bottom);
Assert.IsTrue(bottomLeftCorner.Rect.X >= 0);
//to the right
MoveCorner(bottomLeftCorner, true, false, 5000, 0);
Assert.IsTrue(bottomLeftCorner.Rect.X <= rightBorder.Rect.X);
//to the left
MoveCorner(bottomLeftCorner, true, false, -5000, 0);
Assert.IsTrue(bottomLeftCorner.Rect.X >= 0);
//up-left
MoveCorner(bottomLeftCorner, true, false, -5000, -5000);
Assert.IsTrue(bottomLeftCorner.Rect.Y >= topBorder.Rect.Y);
Assert.IsTrue(bottomLeftCorner.Rect.X >= 0);
//up-right
MoveCorner(bottomLeftCorner, true, false, 5000, -5000);
Assert.IsTrue(bottomLeftCorner.Rect.Y >= topBorder.Rect.Y);
Assert.IsTrue(bottomLeftCorner.Rect.X <= rightBorder.Rect.X);
}
[TestMethod]
public void MoveBottomRightCorner()
{
WindowsElement bottomRightCorner = session.FindElementByAccessibilityId("SEResize");
WindowsElement topBorder = session.FindElementByAccessibilityId("NResize");
WindowsElement leftBorder = session.FindElementByAccessibilityId("WResize");
Assert.IsNotNull(bottomRightCorner);
Assert.IsNotNull(topBorder);
Assert.IsNotNull(leftBorder);
//to the right
MoveCorner(bottomRightCorner, false, false, 5000, 0);
Assert.IsTrue(bottomRightCorner.Rect.X <= Screen.PrimaryScreen.WorkingArea.Right);
//to the left
MoveCorner(bottomRightCorner, false, false, -5000, 0);
Assert.IsTrue(bottomRightCorner.Rect.X >= leftBorder.Rect.X);
//down
MoveCorner(bottomRightCorner, false, false, 0, 5000);
Assert.IsTrue(bottomRightCorner.Rect.Y <= Screen.PrimaryScreen.WorkingArea.Bottom);
//up
MoveCorner(bottomRightCorner, false, false, 0, -5000);
Assert.IsTrue(bottomRightCorner.Rect.Y >= topBorder.Rect.Y);
//up-left
MoveCorner(bottomRightCorner, false, false, -5000, -5000);
Assert.IsTrue(bottomRightCorner.Rect.Y >= topBorder.Rect.Y);
Assert.IsTrue(bottomRightCorner.Rect.X >= leftBorder.Rect.X);
//up-right
MoveCorner(bottomRightCorner, false, false, 5000, -5000);
Assert.IsTrue(bottomRightCorner.Rect.Y >= topBorder.Rect.Y);
Assert.IsTrue(bottomRightCorner.Rect.X <= Screen.PrimaryScreen.WorkingArea.Right);
//down-right
MoveCorner(bottomRightCorner, false, false, 5000, 5000);
Assert.IsTrue(bottomRightCorner.Rect.Y <= Screen.PrimaryScreen.WorkingArea.Bottom);
Assert.IsTrue(bottomRightCorner.Rect.X <= Screen.PrimaryScreen.WorkingArea.Right);
//down-left
MoveCorner(bottomRightCorner, false, false, -5000, 5000);
Assert.IsTrue(bottomRightCorner.Rect.Y <= Screen.PrimaryScreen.WorkingArea.Bottom);
Assert.IsTrue(bottomRightCorner.Rect.X >= leftBorder.Rect.X);
}
[ClassInitialize]
public static void ClassInitialize(TestContext context)
{
Setup(context, false);
ResetSettings();
if (!isPowerToysLaunched)
{
LaunchPowerToys();
}
OpenEditor();
OpenCustomLayouts();
//create canvas zone
OpenCreatorWindow("Create new custom", "Custom layout creator");
session.FindElementByAccessibilityId("newZoneButton").Click();
}
[ClassCleanup]
public static void ClassCleanup()
{
new Actions(session).MoveToElement(session.FindElementByXPath("//Button[@Name=\"Cancel\"]")).Click().Perform();
CloseEditor();
TearDown();
}
[TestInitialize]
public void TestInitialize()
{
}
[TestCleanup]
public void TestCleanup()
{
}
}
}

View File

@ -0,0 +1,323 @@
using System.IO;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Newtonsoft.Json.Linq;
using OpenQA.Selenium;
using OpenQA.Selenium.Appium.Windows;
using OpenQA.Selenium.Interactions;
namespace PowerToysTests
{
[TestClass]
public class FancyZonesEditorCustomLayoutsTests : FancyZonesEditor
{
private void SetLayoutName(string name)
{
WindowsElement textBox = session.FindElementByClassName("TextBox");
textBox.Click();
textBox.SendKeys(Keys.Control + "a");
textBox.SendKeys(Keys.Backspace);
textBox.SendKeys(name);
}
private void CancelTest()
{
WindowsElement cancelButton = session.FindElementByXPath("//Window[@Name=\"FancyZones Editor\"]/Window/Button[@Name=\"Cancel\"]");
new Actions(session).MoveToElement(cancelButton).Click().Perform();
ShortWait();
Assert.AreEqual(_initialZoneSettings, File.ReadAllText(_zoneSettingsPath), "Settings were changed");
}
private void SaveTest(string type, string name, int zoneCount)
{
new Actions(session).MoveToElement(session.FindElementByName("Save and apply")).Click().Perform();
ShortWait();
JObject settings = JObject.Parse(File.ReadAllText(_zoneSettingsPath));
Assert.AreEqual(name, settings["custom-zone-sets"][0]["name"]);
Assert.AreEqual(settings["custom-zone-sets"][0]["uuid"], settings["devices"][0]["active-zoneset"]["uuid"]);
Assert.AreEqual(type, settings["custom-zone-sets"][0]["type"]);
Assert.AreEqual(zoneCount, settings["custom-zone-sets"][0]["info"]["zones"].ToObject<JArray>().Count);
}
[TestMethod]
public void CreateCancel()
{
OpenCreatorWindow("Create new custom", "Custom layout creator");
ZoneCountTest(0, 0);
session.FindElementByAccessibilityId("newZoneButton").Click();
ZoneCountTest(1, 0);
CancelTest();
}
[TestMethod]
public void CreateEmpty()
{
OpenCreatorWindow("Create new custom", "Custom layout creator");
ZoneCountTest(0, 0);
SaveTest("canvas", "Custom Layout 1", 0);
}
[TestMethod]
public void CreateSingleZone()
{
OpenCreatorWindow("Create new custom", "Custom layout creator");
ZoneCountTest(0, 0);
session.FindElementByAccessibilityId("newZoneButton").Click();
ZoneCountTest(1, 0);
SaveTest("canvas", "Custom Layout 1", 1);
}
[TestMethod]
public void CreateManyZones()
{
OpenCreatorWindow("Create new custom", "Custom layout creator");
ZoneCountTest(0, 0);
const int expectedZoneCount = 20;
WindowsElement addButton = session.FindElementByAccessibilityId("newZoneButton");
for (int i = 0; i < expectedZoneCount; i++)
{
addButton.Click();
}
ZoneCountTest(expectedZoneCount, 0);
SaveTest("canvas", "Custom Layout 1", expectedZoneCount);
}
[TestMethod]
public void CreateDeleteZone()
{
OpenCreatorWindow("Create new custom", "Custom layout creator");
ZoneCountTest(0, 0);
WindowsElement addButton = session.FindElementByAccessibilityId("newZoneButton");
for (int i = 0; i < 10; i++)
{
//add zone
addButton.Click();
WindowsElement zone = session.FindElementByClassName("CanvasZone");
Assert.IsNotNull(zone, "Zone was not created");
Assert.IsTrue(zone.Displayed, "Zone was not displayed");
//remove zone
zone.FindElementByClassName("Button").Click();
}
ZoneCountTest(0, 0);
CancelTest();
}
[TestMethod]
public void CreateWithName()
{
OpenCreatorWindow("Create new custom", "Custom layout creator");
string name = "My custom zone layout name";
SetLayoutName(name);
SaveTest("canvas", name, 0);
}
[TestMethod]
public void CreateWithEmptyName()
{
OpenCreatorWindow("Create new custom", "Custom layout creator");
string name = "";
SetLayoutName(name);
SaveTest("canvas", name, 0);
}
[TestMethod]
public void CreateWithUnicodeCharactersName()
{
OpenCreatorWindow("Create new custom", "Custom layout creator");
string name = "ёÖ±¬āݾᵩὡ√ﮘﻹտ";
SetLayoutName(name);
SaveTest("canvas", name, 0);
}
[TestMethod]
public void RenameLayout()
{
//create layout
OpenCreatorWindow("Create new custom", "Custom layout creator");
string name = "My custom zone layout name";
SetLayoutName(name);
SaveTest("canvas", name, 0);
ShortWait();
//rename layout
OpenEditor();
OpenCustomLayouts();
OpenCreatorWindow(name, "Custom layout creator");
name = "New name";
SetLayoutName(name);
SaveTest("canvas", name, 0);
}
[TestMethod]
public void RemoveLayout()
{
//create layout
OpenCreatorWindow("Create new custom", "Custom layout creator");
string name = "Name";
SetLayoutName(name);
SaveTest("canvas", name, 0);
ShortWait();
//save layout id
JObject settings = JObject.Parse(File.ReadAllText(_zoneSettingsPath));
Assert.AreEqual(1, settings["custom-zone-sets"].ToObject<JArray>().Count);
string layoutId = settings["custom-zone-sets"][0]["uuid"].ToString();
//remove layout
OpenEditor();
OpenCustomLayouts();
WindowsElement nameLabel = session.FindElementByXPath("//Text[@Name=\"" + name + "\"]");
new Actions(session).MoveToElement(nameLabel).MoveByOffset(nameLabel.Rect.Width / 2 + 10, 0).Click().Perform();
//settings are saved on window closing
new Actions(session).MoveToElement(session.FindElementByAccessibilityId("PART_Close")).Click().Perform();
ShortWait();
//check settings
settings = JObject.Parse(File.ReadAllText(_zoneSettingsPath));
Assert.AreEqual(0, settings["custom-zone-sets"].ToObject<JArray>().Count);
foreach (JObject device in settings["devices"].ToObject<JArray>())
{
Assert.AreNotEqual(layoutId, device["active-zoneset"]["uuid"], "Deleted layout still applied");
}
}
[TestMethod]
public void AddRemoveSameLayoutNames()
{
string name = "Name";
for (int i = 0; i < 3; i++)
{
//create layout
OpenCreatorWindow("Create new custom", "Custom layout creator");
SetLayoutName(name);
new Actions(session).MoveToElement(session.FindElementByName("Save and apply")).Click().Perform();
ShortWait();
//remove layout
OpenEditor();
OpenCustomLayouts();
WindowsElement nameLabel = session.FindElementByXPath("//Text[@Name=\"" + name + "\"]");
new Actions(session).MoveToElement(nameLabel).MoveByOffset(nameLabel.Rect.Width / 2 + 10, 0).Click().Perform();
}
//settings are saved on window closing
new Actions(session).MoveToElement(session.FindElementByAccessibilityId("PART_Close")).Click().Perform();
ShortWait();
//check settings
JObject settings = JObject.Parse(File.ReadAllText(_zoneSettingsPath));
Assert.AreEqual(0, settings["custom-zone-sets"].ToObject<JArray>().Count);
}
[TestMethod]
public void AddRemoveDifferentLayoutNames()
{
for (int i = 0; i < 3; i++)
{
string name = i.ToString();
//create layout
OpenCreatorWindow("Create new custom", "Custom layout creator");
SetLayoutName(name);
new Actions(session).MoveToElement(session.FindElementByName("Save and apply")).Click().Perform();
ShortWait();
//remove layout
OpenEditor();
OpenCustomLayouts();
WindowsElement nameLabel = session.FindElementByXPath("//Text[@Name=\"" + name + "\"]");
new Actions(session).MoveToElement(nameLabel).MoveByOffset(nameLabel.Rect.Width / 2 + 10, 0).Click().Perform();
}
//settings are saved on window closing
new Actions(session).MoveToElement(session.FindElementByAccessibilityId("PART_Close")).Click().Perform();
ShortWait();
//check settings
JObject settings = JObject.Parse(File.ReadAllText(_zoneSettingsPath));
Assert.AreEqual(0, settings["custom-zone-sets"].ToObject<JArray>().Count);
}
[TestMethod]
public void RemoveApply()
{
string name = "Name";
//create layout
OpenCreatorWindow("Create new custom", "Custom layout creator");
SetLayoutName(name);
new Actions(session).MoveToElement(session.FindElementByName("Save and apply")).Click().Perform();
ShortWait();
//save layout id
JObject settings = JObject.Parse(File.ReadAllText(_zoneSettingsPath));
Assert.AreEqual(1, settings["custom-zone-sets"].ToObject<JArray>().Count);
string layoutId = settings["custom-zone-sets"][0]["uuid"].ToString();
//remove layout
OpenEditor();
OpenCustomLayouts();
WindowsElement nameLabel = session.FindElementByXPath("//Text[@Name=\"" + name + "\"]");
new Actions(session).MoveToElement(nameLabel).MoveByOffset(nameLabel.Rect.Width / 2 + 10, 0).Click().Perform();
//apply
new Actions(session).MoveToElement(session.FindElementByName("Apply")).Click().Perform();
ShortWait();
//check settings
settings = JObject.Parse(File.ReadAllText(_zoneSettingsPath));
Assert.AreEqual(0, settings["custom-zone-sets"].ToObject<JArray>().Count);
foreach (JObject device in settings["devices"].ToObject<JArray>())
{
Assert.AreNotEqual(layoutId, device["active-zoneset"]["uuid"], "Deleted layout still applied");
}
}
[ClassInitialize]
public static void ClassInitialize(TestContext context)
{
Setup(context, false);
ResetSettings();
}
[ClassCleanup]
public static void ClassCleanup()
{
TearDown();
}
[TestInitialize]
public void TestInitialize()
{
if (!isPowerToysLaunched)
{
LaunchPowerToys();
}
OpenEditor();
OpenCustomLayouts();
}
[TestCleanup]
public void TestCleanup()
{
CloseEditor();
ResetDefautZoneSettings(false);
}
}
}

View File

@ -0,0 +1,387 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenQA.Selenium.Appium;
using OpenQA.Selenium.Appium.Windows;
using OpenQA.Selenium.Interactions;
using System;
using System.Collections.ObjectModel;
using System.Windows.Forms;
namespace PowerToysTests
{
[TestClass]
public class FancyZonesEditorGridZoneResizeTests : FancyZonesEditor
{
private const int moveStep = 5;
private void Move(AppiumWebElement thumb, int border, bool moveAscending, bool moveHorizontally, int clickShift = 0)
{
Actions action = new Actions(session);
action.MoveToElement(thumb).MoveByOffset(0, clickShift).ClickAndHold();
int thumbCenter = 0;
if (moveHorizontally)
{
thumbCenter = thumb.Rect.X + thumb.Rect.Width / 2;
}
else
{
thumbCenter = thumb.Rect.Y + thumb.Rect.Height / 2;
}
int moves = Math.Abs(thumbCenter - border) / moveStep;
for (int j = 0; j < moves; j++)
{
int step = moveAscending ? moveStep : -moveStep;
if (moveHorizontally)
{
action.MoveByOffset(step, 0);
}
else
{
action.MoveByOffset(0, step);
}
}
action.Release().Perform();
}
[TestMethod]
public void MoveVerticalSplitter()
{
OpenCreatorWindow("Columns", "Custom table layout creator", "EditTemplateButton");
WindowsElement gridEditor = session.FindElementByClassName("GridEditor");
Assert.IsNotNull(gridEditor);
Assert.AreEqual(3, session.FindElementsByClassName("GridZone").Count);
ReadOnlyCollection<AppiumWebElement> thumbs = gridEditor.FindElementsByClassName("Thumb");
Assert.AreEqual(2, thumbs.Count);
//move left
for (int i = 0; i < thumbs.Count; i++)
{
AppiumWebElement thumb = thumbs[i];
int border = i == 0 ? 0 : thumbs[i - 1].Rect.Right;
Move(thumb, border, false, true);
Assert.IsTrue(thumb.Rect.Left - border <= moveStep);
Assert.IsTrue(thumb.Rect.Right > border);
}
//move right
for (int i = thumbs.Count - 1; i >= 0; i--)
{
AppiumWebElement thumb = thumbs[i];
int border = i == thumbs.Count - 1 ? Screen.PrimaryScreen.WorkingArea.Right : thumbs[i + 1].Rect.Left;
Move(thumb, border, true, true);
Assert.IsTrue(border - thumb.Rect.Right <= moveStep);
Assert.IsTrue(thumb.Rect.Left < border);
}
//move up
foreach (AppiumWebElement thumb in thumbs)
{
int expected = thumb.Rect.X;
Move(thumb, 0, false, false);
int actual = thumb.Rect.X;
Assert.AreEqual(expected, actual);
}
//move down
foreach (AppiumWebElement thumb in thumbs)
{
int expected = thumb.Rect.X;
Move(thumb, Screen.PrimaryScreen.WorkingArea.Right, false, false);
int actual = thumb.Rect.X;
Assert.AreEqual(expected, actual);
}
}
[TestMethod]
public void MoveHorizontalSplitter()
{
OpenCreatorWindow("Rows", "Custom table layout creator", "EditTemplateButton");
WindowsElement gridEditor = session.FindElementByClassName("GridEditor");
Assert.IsNotNull(gridEditor);
Assert.AreEqual(3, session.FindElementsByClassName("GridZone").Count);
ReadOnlyCollection<AppiumWebElement> thumbs = gridEditor.FindElementsByClassName("Thumb");
Assert.AreEqual(2, thumbs.Count);
//move up
for (int i = 0; i < thumbs.Count; i++)
{
AppiumWebElement thumb = thumbs[i];
int border = i == 0 ? 0 : thumbs[i - 1].Rect.Bottom;
Move(thumb, border, false, false);
Assert.IsTrue(thumb.Rect.Top - border <= moveStep);
Assert.IsTrue(thumb.Rect.Right > border);
}
//move down
for (int i = thumbs.Count - 1; i >= 0; i--)
{
AppiumWebElement thumb = thumbs[i];
int border = i == thumbs.Count - 1 ? Screen.PrimaryScreen.WorkingArea.Bottom : thumbs[i + 1].Rect.Top;
Move(thumb, border, true, false);
Assert.IsTrue(border - thumb.Rect.Bottom <= moveStep);
Assert.IsTrue(thumb.Rect.Top < border);
}
//move left
foreach (AppiumWebElement thumb in thumbs)
{
int expected = thumb.Rect.Y;
Move(thumb, 0, false, true);
int actual = thumb.Rect.Y;
Assert.AreEqual(expected, actual);
}
//move right
foreach (AppiumWebElement thumb in thumbs)
{
int expected = thumb.Rect.Y;
Move(thumb, Screen.PrimaryScreen.WorkingArea.Right, true, true);
int actual = thumb.Rect.Y;
Assert.AreEqual(expected, actual);
}
}
[TestMethod]
public void CreateSplitter()
{
OpenCreatorWindow("Columns", "Custom table layout creator", "EditTemplateButton");
WindowsElement gridEditor = session.FindElementByClassName("GridEditor");
Assert.IsNotNull(gridEditor);
ReadOnlyCollection<AppiumWebElement> thumbs = gridEditor.FindElementsByClassName("Thumb");
Assert.AreEqual(3, session.FindElementsByClassName("GridZone").Count);
Assert.AreEqual(2, thumbs.Count);
new Actions(session).MoveToElement(thumbs[0]).MoveByOffset(-30, 0).Click().Perform();
Assert.AreEqual(3, gridEditor.FindElementsByClassName("Thumb").Count);
ReadOnlyCollection<WindowsElement> zones = session.FindElementsByClassName("GridZone");
Assert.AreEqual(4, zones.Count);
//check that zone was splitted horizontally
Assert.AreNotEqual(zones[0].Rect.Height, zones[1].Rect.Height);
Assert.AreNotEqual(zones[3].Rect.Height, zones[1].Rect.Height);
Assert.AreEqual(zones[1].Rect.Height, zones[2].Rect.Height);
}
[TestMethod]
public void CreateSplitterWithShiftPressed()
{
OpenCreatorWindow("Columns", "Custom table layout creator", "EditTemplateButton");
WindowsElement gridEditor = session.FindElementByClassName("GridEditor");
Assert.IsNotNull(gridEditor);
ReadOnlyCollection<AppiumWebElement> thumbs = gridEditor.FindElementsByClassName("Thumb");
Assert.AreEqual(3, session.FindElementsByClassName("GridZone").Count);
Assert.AreEqual(2, thumbs.Count);
new Actions(session).MoveToElement(thumbs[0]).MoveByOffset(-100, 0)
.KeyDown(OpenQA.Selenium.Keys.Shift).Click().KeyUp(OpenQA.Selenium.Keys.Shift)
.Perform();
Assert.AreEqual(3, gridEditor.FindElementsByClassName("Thumb").Count);
ReadOnlyCollection<WindowsElement> zones = session.FindElementsByClassName("GridZone");
Assert.AreEqual(4, zones.Count);
//check that zone was splitted vertically
Assert.AreEqual(zones[0].Rect.Height, zones[1].Rect.Height);
Assert.AreEqual(zones[1].Rect.Height, zones[2].Rect.Height);
Assert.AreEqual(zones[2].Rect.Height, zones[3].Rect.Height);
}
[TestMethod]
public void CreateSplitterWithShiftPressedFocusOnGridEditor()
{
OpenCreatorWindow("Columns", "Custom table layout creator", "EditTemplateButton");
WindowsElement gridEditor = session.FindElementByClassName("GridEditor");
Assert.IsNotNull(gridEditor);
ReadOnlyCollection<AppiumWebElement> thumbs = gridEditor.FindElementsByClassName("Thumb");
Assert.AreEqual(3, session.FindElementsByClassName("GridZone").Count);
Assert.AreEqual(2, thumbs.Count);
new Actions(session).MoveToElement(thumbs[0]).Click().MoveByOffset(-100, 0)
.KeyDown(OpenQA.Selenium.Keys.Shift).Click().KeyUp(OpenQA.Selenium.Keys.Shift)
.Perform();
Assert.AreEqual(3, gridEditor.FindElementsByClassName("Thumb").Count);
ReadOnlyCollection<WindowsElement> zones = session.FindElementsByClassName("GridZone");
Assert.AreEqual(4, zones.Count);
//check that zone was splitted vertically
Assert.AreEqual(zones[0].Rect.Height, zones[1].Rect.Height);
Assert.AreEqual(zones[1].Rect.Height, zones[2].Rect.Height);
Assert.AreEqual(zones[2].Rect.Height, zones[3].Rect.Height);
}
[TestMethod]
public void MoveHorizontallyWithLimiter()
{
OpenCreatorWindow("Columns", "Custom table layout creator", "EditTemplateButton");
WindowsElement gridEditor = session.FindElementByClassName("GridEditor");
Assert.IsNotNull(gridEditor);
Assert.AreEqual(3, session.FindElementsByClassName("GridZone").Count);
ReadOnlyCollection<AppiumWebElement> thumbs = gridEditor.FindElementsByClassName("Thumb");
Assert.AreEqual(2, thumbs.Count);
//create new zones
new Actions(session).MoveToElement(thumbs[0]).Click().MoveByOffset(-30, 0)
.KeyDown(OpenQA.Selenium.Keys.Shift).Click().KeyUp(OpenQA.Selenium.Keys.Shift)
.Perform();
thumbs = gridEditor.FindElementsByClassName("Thumb");
Assert.AreEqual(4, session.FindElementsByClassName("GridZone").Count);
Assert.AreEqual(3, thumbs.Count);
//move thumbs
AppiumWebElement limiter = gridEditor.FindElementsByClassName("Thumb")[0];
AppiumWebElement movable = gridEditor.FindElementsByClassName("Thumb")[1];
Move(movable, 0, false, true);
Assert.IsTrue(movable.Rect.X > limiter.Rect.X);
Assert.IsTrue(movable.Rect.X - limiter.Rect.X < movable.Rect.Width);
Move(limiter, limiter.Rect.X - (limiter.Rect.X / 2), false, true);
Move(movable, 0, false, true);
Assert.IsTrue(movable.Rect.X > limiter.Rect.X);
Assert.IsTrue(movable.Rect.X - limiter.Rect.X < movable.Rect.Width);
}
[TestMethod]
public void MoveVerticallyWithLimiter()
{
OpenCreatorWindow("Rows", "Custom table layout creator", "EditTemplateButton");
WindowsElement gridEditor = session.FindElementByClassName("GridEditor");
Assert.IsNotNull(gridEditor);
Assert.AreEqual(3, session.FindElementsByClassName("GridZone").Count);
ReadOnlyCollection<AppiumWebElement> thumbs = gridEditor.FindElementsByClassName("Thumb");
Assert.AreEqual(2, thumbs.Count);
//create new zones
new Actions(session).MoveToElement(thumbs[0]).Click().MoveByOffset(0, -(thumbs[0].Rect.Y / 2))
.KeyDown(OpenQA.Selenium.Keys.Shift).Click().KeyUp(OpenQA.Selenium.Keys.Shift)
.Perform();
thumbs = gridEditor.FindElementsByClassName("Thumb");
Assert.AreEqual(4, session.FindElementsByClassName("GridZone").Count);
Assert.AreEqual(3, thumbs.Count);
//move thumbs
AppiumWebElement limiter = gridEditor.FindElementsByClassName("Thumb")[0];
AppiumWebElement movable = gridEditor.FindElementsByClassName("Thumb")[1];
Move(movable, 0, false, false);
Assert.IsTrue(movable.Rect.Y > limiter.Rect.Y);
Assert.IsTrue(movable.Rect.Y - limiter.Rect.Y < movable.Rect.Height);
Move(limiter, limiter.Rect.Y - (limiter.Rect.Y / 2), false, false, -5);
Move(movable, 0, false, false);
Assert.IsTrue(movable.Rect.Y > limiter.Rect.Y);
Assert.IsTrue(movable.Rect.Y - limiter.Rect.Y < movable.Rect.Height);
}
[TestMethod]
public void MergeZones()
{
OpenCreatorWindow("Columns", "Custom table layout creator", "EditTemplateButton");
WindowsElement gridEditor = session.FindElementByClassName("GridEditor");
Assert.IsNotNull(gridEditor);
ReadOnlyCollection<WindowsElement> zones = session.FindElementsByClassName("GridZone");
ReadOnlyCollection<AppiumWebElement> thumbs = gridEditor.FindElementsByClassName("Thumb");
Assert.AreEqual(3, zones.Count);
Assert.AreEqual(2, thumbs.Count);
Move(zones[0], thumbs[0].Rect.X + thumbs[0].Rect.Width + 10, true, true, -(zones[0].Rect.Height / 2) + 10);
WindowsElement mergeButton = session.FindElementByName("Merge zones");
Assert.IsNotNull(mergeButton, "Cannot merge: no merge button");
new Actions(session).Click(mergeButton).Perform();
Assert.AreEqual(2, session.FindElementsByClassName("GridZone").Count);
Assert.AreEqual(1, gridEditor.FindElementsByClassName("Thumb").Count);
}
[TestMethod]
public void MoveAfterMerge()
{
OpenCreatorWindow("Columns", "Custom table layout creator", "EditTemplateButton");
WindowsElement gridEditor = session.FindElementByClassName("GridEditor");
Assert.IsNotNull(gridEditor);
ReadOnlyCollection<AppiumWebElement> thumbs = gridEditor.FindElementsByClassName("Thumb");
//create new zones
new Actions(session).MoveToElement(thumbs[0]).Click().MoveByOffset(-(thumbs[0].Rect.X / 2), 0)
.KeyDown(OpenQA.Selenium.Keys.Shift).Click().KeyUp(OpenQA.Selenium.Keys.Shift)
.Perform();
thumbs = gridEditor.FindElementsByClassName("Thumb");
//merge zones
ReadOnlyCollection<WindowsElement> zones = session.FindElementsByClassName("GridZone");
Move(zones[0], thumbs[0].Rect.X + thumbs[0].Rect.Width + 10, true, true, -(zones[0].Rect.Height / 2) + 10);
WindowsElement mergeButton = session.FindElementByName("Merge zones");
Assert.IsNotNull(mergeButton, "Cannot merge: no merge button");
new Actions(session).Click(mergeButton).Perform();
//move thumb
AppiumWebElement thumb = thumbs[1]; //thumb from merged zone is still present
Move(thumb, 0, false, true);
Assert.IsTrue(thumb.Rect.Left <= moveStep);
Assert.IsTrue(thumb.Rect.Right > 0);
}
[ClassInitialize]
public static void ClassInitialize(TestContext context)
{
Setup(context, false);
ResetSettings();
if (!isPowerToysLaunched)
{
LaunchPowerToys();
}
OpenEditor();
OpenTemplates();
}
[ClassCleanup]
public static void ClassCleanup()
{
CloseEditor();
TearDown();
}
[TestInitialize]
public void TestInitialize()
{
}
[TestCleanup]
public void TestCleanup()
{
WindowsElement cancelButton = session.FindElementByXPath("//Window[@Name=\"FancyZones Editor\"]/Window/Button[@Name=\"Cancel\"]");
Assert.IsNotNull(cancelButton);
new Actions(session).MoveToElement(cancelButton).Click().Perform();
}
}
}

View File

@ -6,21 +6,8 @@ using OpenQA.Selenium.Interactions;
namespace PowerToysTests
{
[TestClass]
public class FancyZonesEditorOpeningTests : PowerToysSession
public class FancyZonesEditorOpeningTests : FancyZonesEditor
{
WindowsElement editorWindow;
static void ResetDefaultFancyZonesSettings()
{
if (!Directory.Exists(_settingsFolderPath))
{
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);
}
void RemoveSettingsFile()
{
File.Delete(_zoneSettingsPath);
@ -251,19 +238,12 @@ namespace PowerToysTests
public static void ClassInitialize(TestContext context)
{
Setup(context, false);
if (isPowerToysLaunched)
{
ExitPowerToys();
}
ResetDefaultFancyZonesSettings();
LaunchPowerToys();
ResetDefaultFancyZonesSettings(true);
}
[ClassCleanup]
public static void ClassCleanup()
{
CloseSettings();
{
ExitPowerToys();
TearDown();
}
@ -277,12 +257,7 @@ namespace PowerToysTests
[TestCleanup]
public void TestCleanup()
{
//Close editor
if (editorWindow != null)
{
editorWindow.SendKeys(OpenQA.Selenium.Keys.Alt + OpenQA.Selenium.Keys.F4);
ShortWait();
}
CloseEditor();
if (!Directory.Exists(_settingsFolderPath))
{

View File

@ -1,32 +1,12 @@
using System.IO;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Newtonsoft.Json.Linq;
using OpenQA.Selenium.Appium.Windows;
using OpenQA.Selenium.Interactions;
namespace PowerToysTests
{
[TestClass]
public class FancyZonesEditorTemplatesApplyTests : PowerToysSession
public class FancyZonesEditorTemplatesApplyTests : FancyZonesEditor
{
WindowsElement editorWindow;
private void OpenEditor()
{
new Actions(session).KeyDown(OpenQA.Selenium.Keys.Command).SendKeys("`").KeyUp(OpenQA.Selenium.Keys.Command).Perform();
ShortWait();
editorWindow = session.FindElementByXPath("//Window[@Name=\"FancyZones Editor\"]");
}
private void OpenTemplates()
{
WindowsElement templatesTab = session.FindElementByName("Templates");
templatesTab.Click();
string isSelected = templatesTab.GetAttribute("SelectionItem.IsSelected");
Assert.AreEqual("True", isSelected, "Templates tab cannot be opened");
}
private void ApplyLayout(string tabName)
{
string elementXPath = "//Text[@Name=\"" + tabName + "\"]";
@ -107,20 +87,7 @@ namespace PowerToysTests
[TestCleanup]
public void TestCleanup()
{
//Close editor
try
{
if (editorWindow != null)
{
editorWindow.SendKeys(OpenQA.Selenium.Keys.Alt + OpenQA.Selenium.Keys.F4);
ShortWait();
}
}
catch (OpenQA.Selenium.WebDriverException)
{
//editor has already closed
}
{
}
}
}

View File

@ -1,42 +1,13 @@
using System.IO;
using System.IO;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Newtonsoft.Json.Linq;
using OpenQA.Selenium.Appium.Windows;
using OpenQA.Selenium.Interactions;
namespace PowerToysTests
{
[TestClass]
public class FancyZonesEditorTemplatesEditTests : PowerToysSession
public class FancyZonesEditorTemplatesEditTests : FancyZonesEditor
{
WindowsElement editorWindow;
private void OpenEditor()
{
new Actions(session).KeyDown(OpenQA.Selenium.Keys.Command).SendKeys("`").KeyUp(OpenQA.Selenium.Keys.Command).Perform();
ShortWait();
editorWindow = session.FindElementByXPath("//Window[@Name=\"FancyZones Editor\"]");
}
private void OpenTemplates()
{
WindowsElement templatesTab = session.FindElementByName("Templates");
templatesTab.Click();
string isSelected = templatesTab.GetAttribute("SelectionItem.IsSelected");
Assert.AreEqual("True", isSelected, "Templates tab cannot be opened");
}
private void OpenCreatorWindow(string tabName, string creatorWindowName)
{
string elementXPath = "//Text[@Name=\"" + tabName + "\"]";
session.FindElementByXPath(elementXPath).Click();
session.FindElementByAccessibilityId("EditTemplateButton").Click();
WindowsElement creatorWindow = session.FindElementByName(creatorWindowName);
Assert.IsNotNull(creatorWindow, "Creator window didn't open");
}
private void ChangeLayout()
{
new Actions(session).MoveToElement(session.FindElementByAccessibilityId("PART_TitleBar")).MoveByOffset(0, -50).Click().Perform();
@ -60,16 +31,10 @@ namespace PowerToysTests
Assert.AreEqual(settings["custom-zone-sets"][0]["uuid"], settings["devices"][0]["active-zoneset"]["uuid"]);
}
private void ZoneCountTest(int canvasZonesCount, int gridZonesCount)
{
Assert.AreEqual(canvasZonesCount, session.FindElementsByClassName("CanvasZone").Count);
Assert.AreEqual(gridZonesCount, session.FindElementsByClassName("GridZone").Count);
}
[TestMethod]
public void EditFocusCancel()
{
OpenCreatorWindow("Focus", "Custom layout creator");
OpenCreatorWindow("Focus", "Custom layout creator", "EditTemplateButton");
ZoneCountTest(3, 0);
session.FindElementByAccessibilityId("newZoneButton").Click();
@ -81,7 +46,7 @@ namespace PowerToysTests
[TestMethod]
public void EditColumnsCancel()
{
OpenCreatorWindow("Columns", "Custom table layout creator");
OpenCreatorWindow("Columns", "Custom table layout creator", "EditTemplateButton");
ZoneCountTest(0, 3);
ChangeLayout();
@ -93,7 +58,7 @@ namespace PowerToysTests
[TestMethod]
public void EditRowsCancel()
{
OpenCreatorWindow("Rows", "Custom table layout creator");
OpenCreatorWindow("Rows", "Custom table layout creator", "EditTemplateButton");
ZoneCountTest(0, 3);
ChangeLayout();
@ -105,7 +70,7 @@ namespace PowerToysTests
[TestMethod]
public void EditGridCancel()
{
OpenCreatorWindow("Grid", "Custom table layout creator");
OpenCreatorWindow("Grid", "Custom table layout creator", "EditTemplateButton");
ZoneCountTest(0, 3);
ChangeLayout();
@ -117,7 +82,7 @@ namespace PowerToysTests
[TestMethod]
public void EditPriorityGridCancel()
{
OpenCreatorWindow("Priority Grid", "Custom table layout creator");
OpenCreatorWindow("Priority Grid", "Custom table layout creator", "EditTemplateButton");
ZoneCountTest(0, 3);
ChangeLayout();
@ -129,7 +94,7 @@ namespace PowerToysTests
[TestMethod]
public void EditFocusSave()
{
OpenCreatorWindow("Focus", "Custom layout creator");
OpenCreatorWindow("Focus", "Custom layout creator", "EditTemplateButton");
ZoneCountTest(3, 0);
session.FindElementByAccessibilityId("newZoneButton").Click();
@ -141,7 +106,7 @@ namespace PowerToysTests
[TestMethod]
public void EditColumnsSave()
{
OpenCreatorWindow("Columns", "Custom table layout creator");
OpenCreatorWindow("Columns", "Custom table layout creator", "EditTemplateButton");
ZoneCountTest(0, 3);
ChangeLayout();
@ -153,7 +118,7 @@ namespace PowerToysTests
[TestMethod]
public void EditRowsSave()
{
OpenCreatorWindow("Rows", "Custom table layout creator");
OpenCreatorWindow("Rows", "Custom table layout creator", "EditTemplateButton");
ZoneCountTest(0, 3);
ChangeLayout();
@ -165,7 +130,7 @@ namespace PowerToysTests
[TestMethod]
public void EditGridSave()
{
OpenCreatorWindow("Grid", "Custom table layout creator");
OpenCreatorWindow("Grid", "Custom table layout creator", "EditTemplateButton");
ZoneCountTest(0, 3);
ChangeLayout();
@ -177,7 +142,7 @@ namespace PowerToysTests
[TestMethod]
public void EditPriorityGridSave()
{
OpenCreatorWindow("Priority Grid", "Custom table layout creator");
OpenCreatorWindow("Priority Grid", "Custom table layout creator", "EditTemplateButton");
ZoneCountTest(0, 3);
ChangeLayout();
@ -190,12 +155,8 @@ namespace PowerToysTests
public static void ClassInitialize(TestContext context)
{
Setup(context, false);
if (isPowerToysLaunched)
{
ExitPowerToys();
}
ResetDefaultFancyZonesSettings(true);
ResetDefaultFancyZonesSettings(false);
ResetDefautZoneSettings(true);
}
[ClassCleanup]

View File

@ -0,0 +1,72 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenQA.Selenium.Appium.Windows;
using OpenQA.Selenium.Interactions;
namespace PowerToysTests
{
public class FancyZonesEditor : PowerToysSession
{
protected static WindowsElement editorWindow;
protected static void ResetSettings()
{
ResetDefaultFancyZonesSettings(false);
ResetDefautZoneSettings(true);
}
protected static void OpenEditor()
{
new Actions(session).KeyDown(OpenQA.Selenium.Keys.Command).SendKeys("`").KeyUp(OpenQA.Selenium.Keys.Command).Perform();
ShortWait();
editorWindow = session.FindElementByXPath("//Window[@Name=\"FancyZones Editor\"]");
}
protected static void CloseEditor()
{
try
{
if (editorWindow != null)
{
editorWindow.SendKeys(OpenQA.Selenium.Keys.Alt + OpenQA.Selenium.Keys.F4);
ShortWait();
}
}
catch (OpenQA.Selenium.WebDriverException)
{
//editor has been already closed
}
}
protected static void OpenCustomLayouts()
{
WindowsElement customsTab = session.FindElementByName("Custom");
customsTab.Click();
string isSelected = customsTab.GetAttribute("SelectionItem.IsSelected");
Assert.AreEqual("True", isSelected, "Custom tab cannot be opened");
}
protected static void OpenTemplates()
{
WindowsElement templatesTab = session.FindElementByName("Templates");
templatesTab.Click();
string isSelected = templatesTab.GetAttribute("SelectionItem.IsSelected");
Assert.AreEqual("True", isSelected, "Templates tab cannot be opened");
}
protected static void OpenCreatorWindow(string tabName, string creatorWindowName, string buttonId = "EditCustomButton")
{
string elementXPath = "//Text[@Name=\"" + tabName + "\"]";
session.FindElementByXPath(elementXPath).Click();
session.FindElementByAccessibilityId(buttonId).Click();
WindowsElement creatorWindow = session.FindElementByName(creatorWindowName);
Assert.IsNotNull(creatorWindow, "Creator window didn't open");
}
protected void ZoneCountTest(int canvasZoneCount, int gridZoneCount)
{
Assert.AreEqual(canvasZoneCount, session.FindElementsByClassName("CanvasZone").Count);
Assert.AreEqual(gridZoneCount, session.FindElementsByClassName("GridZone").Count);
}
}
}

View File

@ -256,7 +256,10 @@ namespace PowerToysTests
string zoneSettings = "{\"app-zone-history\":[],\"devices\":[],\"custom-zone-sets\":[]}";
File.WriteAllText(_zoneSettingsPath, zoneSettings);
ExitPowerToys();
if (isPowerToysLaunched)
{
ExitPowerToys();
}
if (relaunch)
{
LaunchPowerToys();

View File

@ -86,10 +86,14 @@
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="FancyZonesTests\EditorCanvasZoneResizeTests.cs" />
<Compile Include="FancyZonesTests\EditorCustomLayoutsTests.cs" />
<Compile Include="FancyZonesTests\EditorGridZoneResizeTests.cs" />
<Compile Include="FancyZonesTests\EditorOpeningTests.cs" />
<Compile Include="FancyZonesTests\EditorSettingsTests.cs" />
<Compile Include="FancyZonesTests\EditorTemplatesApplyTests.cs" />
<Compile Include="FancyZonesTests\EditorTemplatesEditTests.cs" />
<Compile Include="FancyZonesTests\FancyZonesEditor.cs" />
<Compile Include="FancyZonesTests\FancyZonesSettingsTests.cs" />
<Compile Include="PowerToysSession.cs" />
<Compile Include="PowerToysTrayTests.cs" />