mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-01-06 20:37:02 +01:00
Compare commits
3 Commits
dev/xiaofe
...
zhaopengwa
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c5221cc648 | ||
|
|
d5afced6c3 | ||
|
|
11da692712 |
@@ -639,6 +639,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AdvancedPaste.UnitTests", "
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AdvancedPaste.FuzzTests", "src\modules\AdvancedPaste\AdvancedPaste.FuzzTests\AdvancedPaste.FuzzTests.csproj", "{7F5B9557-5878-4438-A721-3E28296BA193}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UITestAPI", "src\UITestAPI\UITestAPI.csproj", "{6190BD46-AF95-49E6-8B7E-89B923CDE845}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|ARM64 = Debug|ARM64
|
||||
@@ -2835,6 +2837,18 @@ Global
|
||||
{7F5B9557-5878-4438-A721-3E28296BA193}.Release|x64.Build.0 = Release|x64
|
||||
{7F5B9557-5878-4438-A721-3E28296BA193}.Release|x86.ActiveCfg = Release|x64
|
||||
{7F5B9557-5878-4438-A721-3E28296BA193}.Release|x86.Build.0 = Release|x64
|
||||
{6190BD46-AF95-49E6-8B7E-89B923CDE845}.Debug|ARM64.ActiveCfg = Debug|ARM64
|
||||
{6190BD46-AF95-49E6-8B7E-89B923CDE845}.Debug|ARM64.Build.0 = Debug|ARM64
|
||||
{6190BD46-AF95-49E6-8B7E-89B923CDE845}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{6190BD46-AF95-49E6-8B7E-89B923CDE845}.Debug|x64.Build.0 = Debug|x64
|
||||
{6190BD46-AF95-49E6-8B7E-89B923CDE845}.Debug|x86.ActiveCfg = Debug|x64
|
||||
{6190BD46-AF95-49E6-8B7E-89B923CDE845}.Debug|x86.Build.0 = Debug|x64
|
||||
{6190BD46-AF95-49E6-8B7E-89B923CDE845}.Release|ARM64.ActiveCfg = Release|ARM64
|
||||
{6190BD46-AF95-49E6-8B7E-89B923CDE845}.Release|ARM64.Build.0 = Release|ARM64
|
||||
{6190BD46-AF95-49E6-8B7E-89B923CDE845}.Release|x64.ActiveCfg = Release|x64
|
||||
{6190BD46-AF95-49E6-8B7E-89B923CDE845}.Release|x64.Build.0 = Release|x64
|
||||
{6190BD46-AF95-49E6-8B7E-89B923CDE845}.Release|x86.ActiveCfg = Release|x64
|
||||
{6190BD46-AF95-49E6-8B7E-89B923CDE845}.Release|x86.Build.0 = Release|x64
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
@@ -3070,6 +3084,7 @@ Global
|
||||
{0DB0F63A-D2F8-4DA3-A650-2D0B8724218E} = {CA716AE6-FE5C-40AC-BB8F-2C87912687AC}
|
||||
{D5E5F5EA-1B6C-4A73-88BE-304F36C9E4EE} = {9873BA05-4C41-4819-9283-CF45D795431B}
|
||||
{7F5B9557-5878-4438-A721-3E28296BA193} = {9873BA05-4C41-4819-9283-CF45D795431B}
|
||||
{6190BD46-AF95-49E6-8B7E-89B923CDE845} = {1AFB6476-670D-4E80-A464-657E01DFF482}
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {C3A2F9D1-7930-4EF4-A6FC-7EE0A99821D0}
|
||||
|
||||
22
src/UITestAPI/UITestAPI.csproj
Normal file
22
src/UITestAPI/UITestAPI.csproj
Normal file
@@ -0,0 +1,22 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net9.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<PublishAot>true</PublishAot>
|
||||
<InvariantGlobalization>true</InvariantGlobalization>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Appium.WebDriver" />
|
||||
<PackageReference Include="MSTest" />
|
||||
<PackageReference Include="System.IO.Abstractions" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Properties\" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -3,64 +3,49 @@
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
|
||||
using Microsoft.FancyZonesEditor.UITests.Utils;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using OpenQA.Selenium;
|
||||
using OpenQA.Selenium.Appium;
|
||||
using OpenQA.Selenium.Appium.Windows;
|
||||
using OpenQA.Selenium.Interactions;
|
||||
|
||||
namespace Microsoft.FancyZonesEditor.UnitTests.Utils
|
||||
namespace Microsoft.UITests.API
|
||||
{
|
||||
public class FancyZonesEditorSession
|
||||
public class UITestAPI
|
||||
{
|
||||
protected const string WindowsApplicationDriverUrl = "http://127.0.0.1:4723";
|
||||
private const string FancyZonesEditorPath = @"\..\..\..\PowerToys.FancyZonesEditor.exe";
|
||||
|
||||
private static FancyZonesEditorFiles? _files;
|
||||
public WindowsDriver<WindowsElement>? Session { get; private set; }
|
||||
|
||||
public static FancyZonesEditorFiles Files
|
||||
public WindowsElement? MainEditorWindow { get; private set; }
|
||||
|
||||
private static Process? appDriver;
|
||||
|
||||
public UITestAPI()
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_files == null)
|
||||
{
|
||||
_files = new FancyZonesEditorFiles();
|
||||
}
|
||||
|
||||
return _files;
|
||||
}
|
||||
}
|
||||
|
||||
public WindowsDriver<WindowsElement>? Session { get; }
|
||||
|
||||
public WindowsElement? MainEditorWindow { get; }
|
||||
|
||||
public FancyZonesEditorSession(TestContext testContext)
|
||||
[UnconditionalSuppressMessage("SingleFile", "IL3000:Avoid accessing Assembly file path when publishing as a single file", Justification = "<Pending>")]
|
||||
public void Init(string exePath)
|
||||
{
|
||||
try
|
||||
{
|
||||
// Launch FancyZonesEditor
|
||||
string? path = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
|
||||
path += FancyZonesEditorPath;
|
||||
string winAppDriverPath = "C:\\Program Files (x86)\\Windows Application Driver\\WinAppDriver.exe";
|
||||
appDriver = Process.Start(winAppDriverPath);
|
||||
|
||||
AppiumOptions opts = new AppiumOptions();
|
||||
opts.AddAdditionalCapability("app", path);
|
||||
Session = new WindowsDriver<WindowsElement>(new Uri(WindowsApplicationDriverUrl), opts);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
testContext.WriteLine(ex.Message);
|
||||
}
|
||||
// Launch Exe
|
||||
string? path = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
|
||||
path += exePath;
|
||||
|
||||
AppiumOptions opts = new AppiumOptions();
|
||||
opts.AddAdditionalCapability("app", path);
|
||||
Session = new WindowsDriver<WindowsElement>(new Uri(WindowsApplicationDriverUrl), opts);
|
||||
|
||||
Assert.IsNotNull(Session, "Session not initialized");
|
||||
|
||||
testContext.WriteLine("Session: " + Session.SessionId.ToString());
|
||||
testContext.WriteLine("Title: " + Session.Title);
|
||||
|
||||
// Set implicit timeout to make element search to retry every 500 ms
|
||||
Session.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(3);
|
||||
|
||||
@@ -93,6 +78,49 @@ namespace Microsoft.FancyZonesEditor.UnitTests.Utils
|
||||
Session.Quit();
|
||||
Session.Dispose();
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
appDriver?.Kill();
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
private WindowsElement? GetElement(string elementName)
|
||||
{
|
||||
var listItem = Session?.FindElementByName(elementName);
|
||||
Assert.IsNotNull(listItem, "ElementName " + elementName + " not found");
|
||||
return listItem;
|
||||
}
|
||||
|
||||
public WindowsElement? NewOpenContextMenu(string elementName)
|
||||
{
|
||||
RightClick_Element(elementName);
|
||||
var menu = Session?.FindElementByClassName("ContextMenu");
|
||||
Assert.IsNotNull(menu, "Context menu not found");
|
||||
return menu;
|
||||
}
|
||||
|
||||
public void Click_Element(string elementName)
|
||||
{
|
||||
var element = GetElement(elementName);
|
||||
Actions actions = new Actions(Session);
|
||||
actions.MoveToElement(element);
|
||||
actions.MoveByOffset(30, 30);
|
||||
actions.Click();
|
||||
actions.Build().Perform();
|
||||
}
|
||||
|
||||
public void RightClick_Element(string elementName)
|
||||
{
|
||||
var element = GetElement(elementName);
|
||||
Actions actions = new Actions(Session);
|
||||
actions.MoveToElement(element);
|
||||
actions.MoveByOffset(30, 30);
|
||||
actions.ContextClick();
|
||||
actions.Build().Perform();
|
||||
}
|
||||
|
||||
private WindowsElement? GetLayout(string layoutName)
|
||||
@@ -88,12 +88,18 @@ namespace FancyZonesEditorCommon.Data
|
||||
return JsonSerializer.Deserialize<JsonElement>(json);
|
||||
}
|
||||
|
||||
public CanvasInfoWrapper CanvasFromJsonElement(string json)
|
||||
public CanvasInfoWrapper CanvasFromJsonElement(JsonElement element)
|
||||
{
|
||||
return JsonSerializer.Deserialize<CanvasInfoWrapper>(json, this.JsonOptions);
|
||||
return new CanvasInfoWrapper
|
||||
{
|
||||
RefWidth = element.GetProperty("RefWidth").GetInt32(),
|
||||
RefHeight = element.GetProperty("RefHeight").GetInt32(),
|
||||
SensitivityRadius = element.TryGetProperty("SensitivityRadius", out JsonElement radius) ? radius.GetInt32() : LayoutDefaultSettings.DefaultSensitivityRadius,
|
||||
Zones = new List<CanvasInfoWrapper.CanvasZoneWrapper>(),
|
||||
};
|
||||
}
|
||||
|
||||
public GridInfoWrapper GridFromJsonElement(string json)
|
||||
public GridInfoWrapper GridFromJsonElement(JsonElement element)
|
||||
{
|
||||
return JsonSerializer.Deserialize<GridInfoWrapper>(json, this.JsonOptions);
|
||||
}
|
||||
|
||||
@@ -3,9 +3,17 @@
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text.Json;
|
||||
|
||||
using FancyZonesEditorCommon.Utils;
|
||||
using static FancyZonesEditorCommon.Data.AppliedLayouts;
|
||||
using static FancyZonesEditorCommon.Data.AppliedLayouts.AppliedLayoutWrapper;
|
||||
using static FancyZonesEditorCommon.Data.CustomLayouts;
|
||||
using static FancyZonesEditorCommon.Data.DefaultLayouts;
|
||||
using static FancyZonesEditorCommon.Data.EditorParameters;
|
||||
using static FancyZonesEditorCommon.Data.LayoutHotkeys;
|
||||
using static FancyZonesEditorCommon.Data.LayoutTemplates;
|
||||
|
||||
namespace FancyZonesEditorCommon.Data
|
||||
{
|
||||
@@ -22,17 +30,221 @@ namespace FancyZonesEditorCommon.Data
|
||||
{
|
||||
return new JsonSerializerOptions
|
||||
{
|
||||
PropertyNamingPolicy = new DashCaseNamingPolicy(),
|
||||
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
|
||||
WriteIndented = true,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public T Read(string file)
|
||||
public AppliedLayoutsListWrapper ReadAppliedLayout(string file)
|
||||
{
|
||||
IOUtils ioUtils = new IOUtils();
|
||||
string data = ioUtils.ReadFile(file);
|
||||
return JsonSerializer.Deserialize<T>(data, JsonOptions);
|
||||
AppliedLayoutsListWrapper res = new AppliedLayoutsListWrapper
|
||||
{
|
||||
AppliedLayouts = new List<AppliedLayoutWrapper>(),
|
||||
};
|
||||
|
||||
using (JsonDocument doc = JsonDocument.Parse(data))
|
||||
{
|
||||
JsonElement root = doc.RootElement;
|
||||
if (root.TryGetProperty("applied-layouts", out JsonElement appliedLayoutsElement) && appliedLayoutsElement.ValueKind == JsonValueKind.Array)
|
||||
{
|
||||
foreach (JsonElement item in appliedLayoutsElement.EnumerateArray())
|
||||
{
|
||||
var device = item.GetProperty("device");
|
||||
var appliedLayout = item.GetProperty("applied-layout");
|
||||
|
||||
res.AppliedLayouts.Add(new AppliedLayoutWrapper
|
||||
{
|
||||
Device = new DeviceIdWrapper
|
||||
{
|
||||
Monitor = device.GetProperty("monitor").GetString(),
|
||||
MonitorInstance = device.GetProperty("monitor-instance").GetString(),
|
||||
MonitorNumber = device.GetProperty("monitor-number").GetInt32(),
|
||||
SerialNumber = device.GetProperty("serial-number").GetString(),
|
||||
VirtualDesktop = device.GetProperty("virtual-desktop").GetString(),
|
||||
},
|
||||
AppliedLayout = new LayoutWrapper
|
||||
{
|
||||
Uuid = appliedLayout.GetProperty("uuid").GetString(),
|
||||
Type = appliedLayout.GetProperty("type").GetString(),
|
||||
ShowSpacing = appliedLayout.GetProperty("show-spacing").GetBoolean(),
|
||||
Spacing = appliedLayout.GetProperty("spacing").GetInt32(),
|
||||
ZoneCount = appliedLayout.GetProperty("zone-count").GetInt32(),
|
||||
SensitivityRadius = appliedLayout.GetProperty("sensitivity-radius").GetInt32(),
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
public ParamsWrapper ReadEditorParams(string file)
|
||||
{
|
||||
IOUtils ioUtils = new IOUtils();
|
||||
string data = ioUtils.ReadFile(file);
|
||||
ParamsWrapper res = new ParamsWrapper()
|
||||
{
|
||||
ProcessId = 0,
|
||||
SpanZonesAcrossMonitors = false,
|
||||
Monitors = new List<NativeMonitorDataWrapper>(),
|
||||
};
|
||||
|
||||
using (JsonDocument doc = JsonDocument.Parse(data))
|
||||
{
|
||||
JsonElement root = doc.RootElement;
|
||||
|
||||
res.ProcessId = root.GetProperty("process-id").GetInt32();
|
||||
res.SpanZonesAcrossMonitors = root.GetProperty("span-zones-across-monitors").GetBoolean();
|
||||
res.Monitors = new List<NativeMonitorDataWrapper>();
|
||||
|
||||
JsonElement monitorsElement = root.GetProperty("monitors");
|
||||
foreach (JsonElement monitorElement in monitorsElement.EnumerateArray())
|
||||
{
|
||||
res.Monitors.Add(new NativeMonitorDataWrapper
|
||||
{
|
||||
Monitor = monitorElement.GetProperty("monitor").GetString(),
|
||||
MonitorInstanceId = monitorElement.GetProperty("monitor-instance-id").GetString(),
|
||||
MonitorSerialNumber = monitorElement.GetProperty("monitor-serial-number").GetString(),
|
||||
MonitorNumber = monitorElement.GetProperty("monitor-number").GetInt32(),
|
||||
VirtualDesktop = monitorElement.GetProperty("virtual-desktop").GetString(),
|
||||
Dpi = monitorElement.GetProperty("dpi").GetInt32(),
|
||||
TopCoordinate = monitorElement.GetProperty("top-coordinate").GetInt32(),
|
||||
LeftCoordinate = monitorElement.GetProperty("left-coordinate").GetInt32(),
|
||||
WorkAreaWidth = monitorElement.GetProperty("work-area-width").GetInt32(),
|
||||
WorkAreaHeight = monitorElement.GetProperty("work-area-height").GetInt32(),
|
||||
MonitorWidth = monitorElement.GetProperty("monitor-width").GetInt32(),
|
||||
MonitorHeight = monitorElement.GetProperty("monitor-height").GetInt32(),
|
||||
IsSelected = monitorElement.GetProperty("is-selected").GetBoolean(),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
public LayoutHotkeysWrapper ReadLayoutHotkeys(string file)
|
||||
{
|
||||
IOUtils ioUtils = new IOUtils();
|
||||
string data = ioUtils.ReadFile(file);
|
||||
LayoutHotkeysWrapper res = new LayoutHotkeysWrapper()
|
||||
{
|
||||
LayoutHotkeys = new List<LayoutHotkeyWrapper>(),
|
||||
};
|
||||
|
||||
using (JsonDocument doc = JsonDocument.Parse(data))
|
||||
{
|
||||
JsonElement root = doc.RootElement;
|
||||
|
||||
JsonElement layoutElements = root.GetProperty("layout-hotkeys");
|
||||
foreach (JsonElement layoutElement in layoutElements.EnumerateArray())
|
||||
{
|
||||
res.LayoutHotkeys.Add(new LayoutHotkeyWrapper
|
||||
{
|
||||
Key = layoutElement.GetProperty("key").GetInt32(),
|
||||
LayoutId = layoutElement.GetProperty("layout-id").GetString(),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
public TemplateLayoutsListWrapper ReadTemplateLayouts(string file)
|
||||
{
|
||||
IOUtils ioUtils = new IOUtils();
|
||||
string data = ioUtils.ReadFile(file);
|
||||
TemplateLayoutsListWrapper res = new TemplateLayoutsListWrapper()
|
||||
{
|
||||
LayoutTemplates = new List<TemplateLayoutWrapper>(),
|
||||
};
|
||||
|
||||
using (JsonDocument doc = JsonDocument.Parse(data))
|
||||
{
|
||||
JsonElement root = doc.RootElement;
|
||||
|
||||
JsonElement layoutElements = root.GetProperty("layout-templates");
|
||||
foreach (JsonElement layoutElement in layoutElements.EnumerateArray())
|
||||
{
|
||||
res.LayoutTemplates.Add(new TemplateLayoutWrapper
|
||||
{
|
||||
Type = layoutElement.GetProperty("type").GetString(),
|
||||
ShowSpacing = layoutElement.GetProperty("show-spacing").GetBoolean(),
|
||||
Spacing = layoutElement.GetProperty("spacing").GetInt32(),
|
||||
ZoneCount = layoutElement.GetProperty("zone-count").GetInt32(),
|
||||
SensitivityRadius = layoutElement.GetProperty("sensitivity-radius").GetInt32(),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
public CustomLayoutListWrapper ReadCustomLayout(string file)
|
||||
{
|
||||
IOUtils ioUtils = new IOUtils();
|
||||
string data = ioUtils.ReadFile(file);
|
||||
CustomLayoutListWrapper res = new CustomLayoutListWrapper()
|
||||
{
|
||||
CustomLayouts = new List<CustomLayoutWrapper>(),
|
||||
};
|
||||
|
||||
using (JsonDocument doc = JsonDocument.Parse(data))
|
||||
{
|
||||
JsonElement root = doc.RootElement;
|
||||
|
||||
JsonElement layoutElements = root.GetProperty("custom-layouts");
|
||||
foreach (JsonElement layoutElement in layoutElements.EnumerateArray())
|
||||
{
|
||||
res.CustomLayouts.Add(new CustomLayoutWrapper
|
||||
{
|
||||
Uuid = layoutElement.GetProperty("uuid").GetString(),
|
||||
Name = layoutElement.GetProperty("name").GetString(),
|
||||
Type = layoutElement.GetProperty("type").GetString(),
|
||||
Info = layoutElement.GetProperty("info"),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
public DefaultLayoutsListWrapper ReadDefaultLayouts(string file)
|
||||
{
|
||||
IOUtils ioUtils = new IOUtils();
|
||||
string data = ioUtils.ReadFile(file);
|
||||
DefaultLayoutsListWrapper res = new DefaultLayoutsListWrapper()
|
||||
{
|
||||
DefaultLayouts = new List<DefaultLayoutWrapper>(),
|
||||
};
|
||||
|
||||
using (JsonDocument doc = JsonDocument.Parse(data))
|
||||
{
|
||||
JsonElement root = doc.RootElement;
|
||||
|
||||
JsonElement layoutElements = root.GetProperty("default-layouts");
|
||||
foreach (JsonElement layoutElement in layoutElements.EnumerateArray())
|
||||
{
|
||||
DefaultLayoutWrapper layout = new DefaultLayoutWrapper
|
||||
{
|
||||
MonitorConfiguration = layoutElement.GetProperty("monitor-configuration").GetString(),
|
||||
Layout = new DefaultLayoutWrapper.LayoutWrapper
|
||||
{
|
||||
Uuid = layoutElement.GetProperty("layout").GetProperty("uuid").GetString(),
|
||||
Type = layoutElement.GetProperty("layout").GetProperty("type").GetString(),
|
||||
ShowSpacing = layoutElement.GetProperty("layout").GetProperty("show-spacing").GetBoolean(),
|
||||
Spacing = layoutElement.GetProperty("layout").GetProperty("spacing").GetInt32(),
|
||||
ZoneCount = layoutElement.GetProperty("layout").GetProperty("zone-count").GetInt32(),
|
||||
SensitivityRadius = layoutElement.GetProperty("layout").GetProperty("sensitivity-radius").GetInt32(),
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
public string Serialize(T data)
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
<PropertyGroup>
|
||||
<Description>PowerToys FancyZonesEditorCommon</Description>
|
||||
<AssemblyName>PowerToys.FancyZonesEditorCommon</AssemblyName>
|
||||
<PublishAot>true</PublishAot>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -1,36 +0,0 @@
|
||||
// Copyright (c) Microsoft Corporation
|
||||
// The Microsoft Corporation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System.Diagnostics;
|
||||
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
|
||||
namespace Microsoft.FancyZonesEditor.UITests
|
||||
{
|
||||
[TestClass]
|
||||
public class Init
|
||||
{
|
||||
private static Process? appDriver;
|
||||
|
||||
[AssemblyInitialize]
|
||||
public static void SetupAll(TestContext context)
|
||||
{
|
||||
string winAppDriverPath = "C:\\Program Files (x86)\\Windows Application Driver\\WinAppDriver.exe";
|
||||
context.WriteLine($"Attempting to launch WinAppDriver at: {winAppDriverPath}");
|
||||
appDriver = Process.Start(winAppDriverPath);
|
||||
}
|
||||
|
||||
[AssemblyCleanup]
|
||||
public static void CleanupAll()
|
||||
{
|
||||
try
|
||||
{
|
||||
appDriver?.Kill();
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,9 @@ using System.Collections.Generic;
|
||||
|
||||
using FancyZonesEditorCommon.Data;
|
||||
using Microsoft.FancyZonesEditor.UITests;
|
||||
using Microsoft.FancyZonesEditor.UITests.Utils;
|
||||
using Microsoft.FancyZonesEditor.UnitTests.Utils;
|
||||
using Microsoft.UITests.API;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
|
||||
namespace UITests_FancyZonesEditor
|
||||
@@ -14,9 +16,22 @@ namespace UITests_FancyZonesEditor
|
||||
[TestClass]
|
||||
public class RunFancyZonesEditorTest
|
||||
{
|
||||
private static FancyZonesEditorSession? _session;
|
||||
private const string FancyZonesEditorPath = @"\..\..\..\PowerToys.FancyZonesEditor.exe";
|
||||
private static FancyZonesEditorFiles? _files;
|
||||
private static UITestAPI? _uITestAPI;
|
||||
|
||||
private static TestContext? _context;
|
||||
|
||||
[AssemblyInitialize]
|
||||
public static void SetupAll(TestContext context)
|
||||
{
|
||||
}
|
||||
|
||||
[AssemblyCleanup]
|
||||
public static void CleanupAll()
|
||||
{
|
||||
}
|
||||
|
||||
[ClassInitialize]
|
||||
public static void ClassInitialize(TestContext testContext)
|
||||
{
|
||||
@@ -48,7 +63,8 @@ namespace UITests_FancyZonesEditor
|
||||
},
|
||||
},
|
||||
};
|
||||
FancyZonesEditorSession.Files.ParamsIOHelper.WriteData(editorParameters.Serialize(parameters));
|
||||
_files = new FancyZonesEditorFiles();
|
||||
_files.ParamsIOHelper.WriteData(editorParameters.Serialize(parameters));
|
||||
|
||||
LayoutTemplates layoutTemplates = new LayoutTemplates();
|
||||
LayoutTemplates.TemplateLayoutsListWrapper templateLayoutsListWrapper = new LayoutTemplates.TemplateLayoutsListWrapper
|
||||
@@ -98,81 +114,89 @@ namespace UITests_FancyZonesEditor
|
||||
},
|
||||
},
|
||||
};
|
||||
FancyZonesEditorSession.Files.LayoutTemplatesIOHelper.WriteData(layoutTemplates.Serialize(templateLayoutsListWrapper));
|
||||
_files.LayoutTemplatesIOHelper.WriteData(layoutTemplates.Serialize(templateLayoutsListWrapper));
|
||||
|
||||
CustomLayouts customLayouts = new CustomLayouts();
|
||||
CustomLayouts.CustomLayoutListWrapper customLayoutListWrapper = new CustomLayouts.CustomLayoutListWrapper
|
||||
{
|
||||
CustomLayouts = new List<CustomLayouts.CustomLayoutWrapper> { },
|
||||
};
|
||||
FancyZonesEditorSession.Files.CustomLayoutsIOHelper.WriteData(customLayouts.Serialize(customLayoutListWrapper));
|
||||
_files.CustomLayoutsIOHelper.WriteData(customLayouts.Serialize(customLayoutListWrapper));
|
||||
|
||||
DefaultLayouts defaultLayouts = new DefaultLayouts();
|
||||
DefaultLayouts.DefaultLayoutsListWrapper defaultLayoutsListWrapper = new DefaultLayouts.DefaultLayoutsListWrapper
|
||||
{
|
||||
DefaultLayouts = new List<DefaultLayouts.DefaultLayoutWrapper> { },
|
||||
};
|
||||
FancyZonesEditorSession.Files.DefaultLayoutsIOHelper.WriteData(defaultLayouts.Serialize(defaultLayoutsListWrapper));
|
||||
_files.DefaultLayoutsIOHelper.WriteData(defaultLayouts.Serialize(defaultLayoutsListWrapper));
|
||||
|
||||
LayoutHotkeys layoutHotkeys = new LayoutHotkeys();
|
||||
LayoutHotkeys.LayoutHotkeysWrapper layoutHotkeysWrapper = new LayoutHotkeys.LayoutHotkeysWrapper
|
||||
{
|
||||
LayoutHotkeys = new List<LayoutHotkeys.LayoutHotkeyWrapper> { },
|
||||
};
|
||||
FancyZonesEditorSession.Files.LayoutHotkeysIOHelper.WriteData(layoutHotkeys.Serialize(layoutHotkeysWrapper));
|
||||
_files.LayoutHotkeysIOHelper.WriteData(layoutHotkeys.Serialize(layoutHotkeysWrapper));
|
||||
|
||||
AppliedLayouts appliedLayouts = new AppliedLayouts();
|
||||
AppliedLayouts.AppliedLayoutsListWrapper appliedLayoutsWrapper = new AppliedLayouts.AppliedLayoutsListWrapper
|
||||
{
|
||||
AppliedLayouts = new List<AppliedLayouts.AppliedLayoutWrapper> { },
|
||||
};
|
||||
FancyZonesEditorSession.Files.AppliedLayoutsIOHelper.WriteData(appliedLayouts.Serialize(appliedLayoutsWrapper));
|
||||
_files.AppliedLayoutsIOHelper.WriteData(appliedLayouts.Serialize(appliedLayoutsWrapper));
|
||||
}
|
||||
|
||||
[ClassCleanup]
|
||||
public static void ClassCleanup()
|
||||
{
|
||||
FancyZonesEditorSession.Files.Restore();
|
||||
_context = null;
|
||||
if (_files != null)
|
||||
{
|
||||
_files.Restore();
|
||||
}
|
||||
}
|
||||
|
||||
[TestInitialize]
|
||||
public void TestInitialize()
|
||||
{
|
||||
_session = new FancyZonesEditorSession(_context!);
|
||||
_uITestAPI = new UITestAPI();
|
||||
_uITestAPI.Init(FancyZonesEditorPath);
|
||||
}
|
||||
|
||||
[TestCleanup]
|
||||
public void TestCleanup()
|
||||
{
|
||||
_session?.Close(_context!);
|
||||
if (_uITestAPI != null && _context != null)
|
||||
{
|
||||
_uITestAPI.Close(_context);
|
||||
}
|
||||
|
||||
_context = null;
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void OpenEditorWindow() // verify the session is initialized
|
||||
{
|
||||
Assert.IsNotNull(_session?.Session);
|
||||
Assert.IsNotNull(_uITestAPI);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void OpenNewLayoutDialog() // verify the new layout dialog is opened
|
||||
{
|
||||
_session?.Click_CreateNewLayout();
|
||||
Assert.IsNotNull(_session?.Session?.FindElementsByName("Choose layout type")); // check the pane header
|
||||
_uITestAPI?.Click_CreateNewLayout();
|
||||
Assert.IsNotNull(_uITestAPI?.Session?.FindElementsByName("Choose layout type")); // check the pane header
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void OpenEditLayoutDialog() // verify the edit layout dialog is opened
|
||||
{
|
||||
_session?.Click_EditLayout(TestConstants.TemplateLayoutNames[Constants.TemplateLayout.Grid]);
|
||||
Assert.IsNotNull(_session?.Session?.FindElementByAccessibilityId("EditLayoutDialogTitle")); // check the pane header
|
||||
Assert.IsNotNull(_session?.Session?.FindElementsByName("Edit 'Grid'")); // verify it's opened for the correct layout
|
||||
_uITestAPI?.Click_EditLayout(TestConstants.TemplateLayoutNames[Constants.TemplateLayout.Grid]);
|
||||
Assert.IsNotNull(_uITestAPI?.Session?.FindElementByAccessibilityId("EditLayoutDialogTitle")); // check the pane header
|
||||
Assert.IsNotNull(_uITestAPI?.Session?.FindElementsByName("Edit 'Grid'")); // verify it's opened for the correct layout
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void OpenContextMenu() // verify the context menu is opened
|
||||
{
|
||||
Assert.IsNotNull(_session?.OpenContextMenu(TestConstants.TemplateLayoutNames[Constants.TemplateLayout.Columns]));
|
||||
Assert.IsNotNull(_uITestAPI?.OpenContextMenu(TestConstants.TemplateLayoutNames[Constants.TemplateLayout.Columns]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Appium.WebDriver" />
|
||||
<PackageReference Include="MSTest" />
|
||||
<PackageReference Include="System.IO.Abstractions" />
|
||||
</ItemGroup>
|
||||
@@ -28,6 +27,7 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\..\UITestAPI\UITestAPI.csproj" />
|
||||
<ProjectReference Include="..\FancyZonesEditorCommon\FancyZonesEditorCommon.csproj" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -39,7 +39,7 @@ namespace FancyZonesEditor.Utils
|
||||
try
|
||||
{
|
||||
EditorParameters parser = new EditorParameters();
|
||||
var editorParams = parser.Read(parser.File);
|
||||
var editorParams = parser.ReadEditorParams(parser.File);
|
||||
|
||||
// Process ID
|
||||
App.PowerToysPID = editorParams.ProcessId;
|
||||
@@ -131,7 +131,7 @@ namespace FancyZonesEditor.Utils
|
||||
try
|
||||
{
|
||||
AppliedLayouts parser = new AppliedLayouts();
|
||||
var appliedLayouts = parser.Read(parser.File);
|
||||
var appliedLayouts = parser.ReadAppliedLayout(parser.File);
|
||||
|
||||
bool parsingResult = SetAppliedLayouts(appliedLayouts.AppliedLayouts);
|
||||
if (!parsingResult)
|
||||
@@ -160,7 +160,7 @@ namespace FancyZonesEditor.Utils
|
||||
return new ParsingResult(true);
|
||||
}
|
||||
|
||||
var layoutHotkeys = parser.Read(parser.File);
|
||||
var layoutHotkeys = parser.ReadLayoutHotkeys(parser.File);
|
||||
bool layoutHotkeysParsingResult = SetLayoutHotkeys(layoutHotkeys);
|
||||
if (!layoutHotkeysParsingResult)
|
||||
{
|
||||
@@ -188,7 +188,7 @@ namespace FancyZonesEditor.Utils
|
||||
return new ParsingResult(true);
|
||||
}
|
||||
|
||||
var templates = parser.Read(parser.File);
|
||||
var templates = parser.ReadTemplateLayouts(parser.File);
|
||||
bool parsingResult = SetTemplateLayouts(templates.LayoutTemplates);
|
||||
if (parsingResult)
|
||||
{
|
||||
@@ -216,7 +216,7 @@ namespace FancyZonesEditor.Utils
|
||||
return new ParsingResult(true);
|
||||
}
|
||||
|
||||
var wrapper = parser.Read(parser.File);
|
||||
var wrapper = parser.ReadCustomLayout(parser.File);
|
||||
bool parsingResult = SetCustomLayouts(wrapper.CustomLayouts);
|
||||
if (parsingResult)
|
||||
{
|
||||
@@ -244,7 +244,7 @@ namespace FancyZonesEditor.Utils
|
||||
return new ParsingResult(true);
|
||||
}
|
||||
|
||||
var wrapper = parser.Read(parser.File);
|
||||
var wrapper = parser.ReadDefaultLayouts(parser.File);
|
||||
bool parsingResult = SetDefaultLayouts(wrapper.DefaultLayouts);
|
||||
if (parsingResult)
|
||||
{
|
||||
@@ -838,7 +838,7 @@ namespace FancyZonesEditor.Utils
|
||||
private CanvasLayoutModel ParseCanvasInfo(CustomLayouts.CustomLayoutWrapper wrapper)
|
||||
{
|
||||
CustomLayouts deserializer = new CustomLayouts();
|
||||
var info = deserializer.CanvasFromJsonElement(wrapper.Info.GetRawText());
|
||||
var info = deserializer.CanvasFromJsonElement(wrapper.Info);
|
||||
|
||||
var zones = new List<Int32Rect>();
|
||||
foreach (var zone in info.Zones)
|
||||
@@ -861,7 +861,7 @@ namespace FancyZonesEditor.Utils
|
||||
private GridLayoutModel ParseGridInfo(CustomLayouts.CustomLayoutWrapper wrapper)
|
||||
{
|
||||
CustomLayouts deserializer = new CustomLayouts();
|
||||
var info = deserializer.GridFromJsonElement(wrapper.Info.GetRawText());
|
||||
var info = deserializer.GridFromJsonElement(wrapper.Info);
|
||||
|
||||
// Check if rows and columns are valid
|
||||
if (info.Rows <= 0 || info.Columns <= 0)
|
||||
|
||||
@@ -6,7 +6,6 @@ using System;
|
||||
using System.Globalization;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Text.Json;
|
||||
|
||||
using global::PowerToys.GPOWrapper;
|
||||
using Microsoft.PowerToys.Settings.UI.Library;
|
||||
using Microsoft.PowerToys.Settings.UI.Library.Helpers;
|
||||
|
||||
Reference in New Issue
Block a user