Skip to content

Commit

Permalink
[WinAppDriver tests] Affection on user setting files fix (#4186)
Browse files Browse the repository at this point in the history
  • Loading branch information
SeraphimaZykova committed Jun 19, 2020
1 parent c78e658 commit 90efc57
Show file tree
Hide file tree
Showing 13 changed files with 315 additions and 190 deletions.
1 change: 1 addition & 0 deletions src/modules/fancyzones/lib/JsonHelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ namespace JSONHelpers
{
std::wstring result = PTSettingsHelper::get_module_save_folder_location(moduleName);
jsonFilePath = result + L"\\" + std::wstring(L"zones-settings.json");
appZoneHistoryFilePath = result + L"\\" + std::wstring(L"app-zone-history.json");
}
#endif

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,9 @@ public void MoveBottomRightCorner()
public static void ClassInitialize(TestContext context)
{
Setup(context, false);
if (session == null)
return;

ResetSettings();

if (!isPowerToysLaunched)
Expand All @@ -281,6 +284,9 @@ public static void ClassCleanup()
[TestInitialize]
public void TestInitialize()
{
if (session == null)
return;

//create canvas zone
OpenCreatorWindow("Create new custom", "Custom layout creator");
session.FindElementByAccessibilityId("newZoneButton").Click();
Expand All @@ -289,6 +295,9 @@ public void TestInitialize()
[TestCleanup]
public void TestCleanup()
{
if (session == null)
return;

new Actions(session).MoveToElement(session.FindElementByXPath("//Button[@Name=\"Cancel\"]")).Click().Perform();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,9 @@ public void RemoveApply()
public static void ClassInitialize(TestContext context)
{
Setup(context, false);
if (session == null)
return;

ResetSettings();
}

Expand All @@ -304,6 +307,9 @@ public static void ClassCleanup()
[TestInitialize]
public void TestInitialize()
{
if (session == null)
return;

if (!isPowerToysLaunched)
{
LaunchPowerToys();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,9 @@ public void MoveAfterMerge()
public static void ClassInitialize(TestContext context)
{
Setup(context, false);
if (session == null)
return;

ResetSettings();

if (!isPowerToysLaunched)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,9 @@ public void OpenEditorByHotkeyCroppedSettings()
public static void ClassInitialize(TestContext context)
{
Setup(context, false);
if (session == null)
return;

ResetDefaultFancyZonesSettings(true);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.IO;
using System.Collections.Generic;
using Microsoft.VisualStudio.TestTools.UnitTesting;
Expand Down Expand Up @@ -179,6 +179,9 @@ private void ClearText(WindowsElement windowsElement)
public static void ClassInitialize(TestContext context)
{
Setup(context, false);
if (session == null)
return;

ResetSettings();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ public void ApplyPriorityGrid()
public static void ClassInitialize(TestContext context)
{
Setup(context, false);
if (session == null)
return;

ResetDefaultFancyZonesSettings(true);
}

Expand All @@ -81,6 +84,9 @@ public static void ClassCleanup()
[TestInitialize]
public void TestInitialize()
{
if (session == null)
return;

OpenEditor();
OpenTemplates();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,9 @@ public void EditPriorityGridSave()
public static void ClassInitialize(TestContext context)
{
Setup(context, false);
if (session == null)
return;

ResetDefaultFancyZonesSettings(false);
ResetDefaultZoneSettings(true);
}
Expand All @@ -171,6 +174,9 @@ public static void ClassCleanup()
[TestInitialize]
public void TestInitialize()
{
if (session == null)
return;

if (!isPowerToysLaunched)
{
LaunchPowerToys();
Expand Down
69 changes: 49 additions & 20 deletions src/tests/win-app-driver/FancyZonesTests/FancyZonesEditor.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenQA.Selenium.Appium.Windows;
using OpenQA.Selenium.Interactions;
using System;

namespace PowerToysTests
{
Expand All @@ -16,13 +17,20 @@ protected static void ResetSettings()

protected static void OpenEditor()
{
new Actions(session).KeyDown(OpenQA.Selenium.Keys.Command).SendKeys("`").KeyUp(OpenQA.Selenium.Keys.Command).Perform();
WaitSeconds(2);
//editorWindow = WaitElementByXPath("//Window[@Name=\"FancyZones Editor\"]");
editorWindow = WaitElementByName("FancyZones Editor");
//may not find editor by name in 0.16.1
//editorWindow = WaitElementByAccessibilityId("MainWindow1");
Assert.IsNotNull(editorWindow, "Couldn't find editor window");
try
{
new Actions(session).KeyDown(OpenQA.Selenium.Keys.Command).SendKeys("`").KeyUp(OpenQA.Selenium.Keys.Command).Perform();
WaitSeconds(2);
//editorWindow = WaitElementByXPath("//Window[@Name=\"FancyZones Editor\"]");
editorWindow = WaitElementByName("FancyZones Editor");
//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()
Expand All @@ -42,28 +50,49 @@ protected static void CloseEditor()

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");
try
{
WindowsElement customsTab = session.FindElementByName("Custom");
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()
{
WindowsElement templatesTab = session.FindElementByName("Templates");
templatesTab.Click();
string isSelected = templatesTab.GetAttribute("SelectionItem.IsSelected");
Assert.AreEqual("True", isSelected, "Templates tab cannot be opened");
try
{
WindowsElement templatesTab = session.FindElementByName("Templates");
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")
{
string elementXPath = "//Text[@Name=\"" + tabName + "\"]";
WaitElementByXPath(elementXPath).Click();
WaitElementByAccessibilityId(buttonId).Click();
try
{
string elementXPath = "//Text[@Name=\"" + tabName + "\"]";
WaitElementByXPath(elementXPath).Click();
WaitElementByAccessibilityId(buttonId).Click();

WindowsElement creatorWindow = WaitElementByName(creatorWindowName);
Assert.IsNotNull(creatorWindow, "Creator window didn't open");
WindowsElement creatorWindow = WaitElementByName(creatorWindowName);
Assert.IsNotNull(creatorWindow, "Creator window didn't open");
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}

protected void ZoneCountTest(int canvasZoneCount, int gridZoneCount)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -713,6 +713,9 @@ public void ConfigureLocalSymbolHotkey()
public static void ClassInitialize(TestContext context)
{
Setup(context);
if (session == null)
return;

Init();
}

Expand Down Expand Up @@ -740,6 +743,9 @@ public static void ClassCleanup()
[TestInitialize]
public void TestInitialize()
{
if (session == null)
return;

try
{
_initialSettingsJson = JObject.Parse(_initialSettings);
Expand Down

0 comments on commit 90efc57

Please sign in to comment.