mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-06 03:07:04 +02:00
WinAppDriver tests update (#5882)
* tray button fix * settings closing changed * ignore old settings tests * changed test init * changed launch * separated app history file * select enabled modules on launch
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
using System.IO;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using OpenQA.Selenium.Appium;
|
||||
using OpenQA.Selenium.Appium.Windows;
|
||||
using OpenQA.Selenium.Interactions;
|
||||
|
||||
@@ -11,6 +12,7 @@ namespace PowerToysTests
|
||||
void RemoveSettingsFile()
|
||||
{
|
||||
File.Delete(_zoneSettingsPath);
|
||||
File.Delete(_appHistoryPath);
|
||||
}
|
||||
|
||||
void RemoveSettingsFolder()
|
||||
@@ -22,44 +24,62 @@ namespace PowerToysTests
|
||||
{
|
||||
string zoneSettings = "";
|
||||
File.WriteAllText(_zoneSettingsPath, zoneSettings);
|
||||
|
||||
string appHistory = "";
|
||||
File.WriteAllText(_appHistoryPath, appHistory);
|
||||
}
|
||||
|
||||
void CreateDefaultSettingsFile()
|
||||
{
|
||||
string zoneSettings = "{\"app-zone-history\":[],\"devices\":[],\"custom-zone-sets\":[]}";
|
||||
string zoneSettings = "{\"devices\":[],\"custom-zone-sets\":[]}";
|
||||
File.WriteAllText(_zoneSettingsPath, zoneSettings);
|
||||
|
||||
string appHistory = "{\"app-zone-history\":[]}";
|
||||
File.WriteAllText(_appHistoryPath, appHistory);
|
||||
}
|
||||
|
||||
void CreateValidSettingsFile()
|
||||
{
|
||||
string zoneSettings = "{\"app-zone-history\":[{\"app-path\":\"C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\Common7\\IDE\\Extensions\\TestPlatform\\testhost.exe\",\"zone-index\":3,\"device-id\":\"DELA026#5&10a58c63&0&UID16777488_1920_1200_{39B25DD2-130D-4B5D-8851-4791D66B1539}\",\"zoneset-uuid\":\"{D13ABB6D-7721-4176-9647-C8C0836D99CC}\"}],\"devices\":[{\"device-id\":\"DELA026#5&10a58c63&0&UID16777488_1920_1200_{39B25DD2-130D-4B5D-8851-4791D66B1539}\",\"active-zoneset\":{\"uuid\":\"{D13ABB6D-7721-4176-9647-C8C0836D99CC}\",\"type\":\"columns\"},\"editor-show-spacing\":true,\"editor-spacing\":16,\"editor-zone-count\":3}],\"custom-zone-sets\":[]}";
|
||||
string zoneSettings = "{\"devices\":[{\"device-id\":\"DELA026#5&10a58c63&0&UID16777488_1920_1200_{39B25DD2-130D-4B5D-8851-4791D66B1539}\",\"active-zoneset\":{\"uuid\":\"{D13ABB6D-7721-4176-9647-C8C0836D99CC}\",\"type\":\"columns\"},\"editor-show-spacing\":true,\"editor-spacing\":16,\"editor-zone-count\":3}],\"custom-zone-sets\":[]}";
|
||||
File.WriteAllText(_zoneSettingsPath, zoneSettings);
|
||||
|
||||
string appHistory = "{\"app-zone-history\":[{\"app-path\":\"C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\Common7\\IDE\\Extensions\\TestPlatform\\testhost.exe\",\"zone-index\":3,\"device-id\":\"DELA026#5&10a58c63&0&UID16777488_1920_1200_{39B25DD2-130D-4B5D-8851-4791D66B1539}\",\"zoneset-uuid\":\"{D13ABB6D-7721-4176-9647-C8C0836D99CC}\"}]}";
|
||||
File.WriteAllText(_appHistoryPath, appHistory);
|
||||
}
|
||||
|
||||
void CreateValidSettingsFileWithUtf8()
|
||||
{
|
||||
string zoneSettings = "{\"app-zone-history\":[{\"app-path\":\"C:\\Program Files (x86)\\йцукен\\testhost.exe\",\"zone-index\":3,\"device-id\":\"DELA026#5&10a58c63&0&UID16777488_1920_1200_{39B25DD2-130D-4B5D-8851-4791D66B1539}\",\"zoneset-uuid\":\"{D13ABB6D-7721-4176-9647-C8C0836D99CC}\"}],\"devices\":[{\"device-id\":\"DELA026#5&10a58c63&0&UID16777488_1920_1200_{39B25DD2-130D-4B5D-8851-4791D66B1539}\",\"active-zoneset\":{\"uuid\":\"{D13ABB6D-7721-4176-9647-C8C0836D99CC}\",\"type\":\"columns\"},\"editor-show-spacing\":true,\"editor-spacing\":16,\"editor-zone-count\":3}],\"custom-zone-sets\":[]}";
|
||||
string zoneSettings = "{\"devices\":[{\"device-id\":\"DELA026#5&10a58c63&0&UID16777488_1920_1200_{39B25DD2-130D-4B5D-8851-4791D66B1539}\",\"active-zoneset\":{\"uuid\":\"{D13ABB6D-7721-4176-9647-C8C0836D99CC}\",\"type\":\"columns\"},\"editor-show-spacing\":true,\"editor-spacing\":16,\"editor-zone-count\":3}],\"custom-zone-sets\":[]}";
|
||||
File.WriteAllText(_zoneSettingsPath, zoneSettings);
|
||||
|
||||
string appHistory = "{\"app-zone-history\":[{\"app-path\":\"C:\\Program Files (x86)\\йцукен\\testhost.exe\",\"zone-index\":3,\"device-id\":\"DELA026#5&10a58c63&0&UID16777488_1920_1200_{39B25DD2-130D-4B5D-8851-4791D66B1539}\",\"zoneset-uuid\":\"{D13ABB6D-7721-4176-9647-C8C0836D99CC}\"}]}";
|
||||
File.WriteAllText(_appHistoryPath, appHistory);
|
||||
}
|
||||
|
||||
void CreateInvalidSettingsFile()
|
||||
{
|
||||
string zoneSettings = "{\"app-zone-history\":[{\"app-path\":\"C:\\Program Files (x86)\\Microsoft Visual Studio\\testhost.exe\",\"zone-index\":3,\"device-id\":\"wrong-device-id\",\"zoneset-uuid\":\"{D13ABB6D-invalid-uuid-C8C0836D99CC}\"}],\"devices\":[{\"device-id\":\"DELA026#5&10a58c63&0&UID16777488_1920_1200_{39B25DD2-130D-4B5D-8851-4791D66B1539}\",\"active-zoneset\":{\"uuid\":\"{D13ABB6D-7721-4176-9647-C8C0836D99CC}\",\"type\":\"columns\"},\"editor-show-spacing\":true,\"editor-spacing\":16,\"editor-zone-count\":3}],\"custom-zone-sets\":[]}";
|
||||
File.WriteAllText(_zoneSettingsPath, zoneSettings);
|
||||
|
||||
string appHistory = "";
|
||||
File.WriteAllText(_appHistoryPath, appHistory);
|
||||
}
|
||||
|
||||
void CreateCroppedSettingsFile()
|
||||
{
|
||||
string zoneSettings = "{\"app-zone-history\":[],\"devices\":[],\"custom-zone-sets\":[{\"uuid\":\"{8BEC7183-C90E-4D41-AD1C-1AC2BC4760BA}\",\"name\":\"";
|
||||
string zoneSettings = "{\"devices\":[],\"custom-zone-sets\":[{\"uuid\":\"{8BEC7183-C90E-4D41-AD1C-1AC2BC4760BA}\",\"name\":\"";
|
||||
File.WriteAllText(_zoneSettingsPath, zoneSettings);
|
||||
|
||||
string appHistory = "{\"app-zone-history\":[]}";
|
||||
File.WriteAllText(_appHistoryPath, appHistory);
|
||||
}
|
||||
|
||||
void TestEditorOpened()
|
||||
void TestEditorOpened(bool errorExpected = false)
|
||||
{
|
||||
WindowsElement errorMessage = null;
|
||||
try
|
||||
{
|
||||
errorMessage = WaitElementByName("FancyZones Editor Exception Handler");
|
||||
errorMessage = session.FindElementByName("FancyZones Editor Exception Handler");
|
||||
if (errorMessage != null)
|
||||
{
|
||||
errorMessage.FindElementByName("OK").Click();
|
||||
@@ -70,34 +90,29 @@ namespace PowerToysTests
|
||||
//no error message, it's ok
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
editorWindow = session.FindElementByXPath("//Window[@Name=\"FancyZones Editor\"]");
|
||||
}
|
||||
catch (OpenQA.Selenium.WebDriverException)
|
||||
{
|
||||
}
|
||||
|
||||
editorWindow = session.FindElementByName("FancyZones Editor");
|
||||
Assert.IsNotNull(editorWindow);
|
||||
Assert.IsNull(errorMessage);
|
||||
|
||||
if (!errorExpected)
|
||||
{
|
||||
Assert.IsNull(errorMessage);
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert.IsNotNull(errorMessage);
|
||||
}
|
||||
}
|
||||
|
||||
void OpenEditorBySettingsButton()
|
||||
{
|
||||
OpenSettings();
|
||||
OpenFancyZonesSettings();
|
||||
|
||||
WindowsElement editorButton = session.FindElementByXPath("//Button[@Name=\"Edit zones\"]");
|
||||
Assert.IsNotNull(editorButton);
|
||||
|
||||
editorButton.Click();
|
||||
TestEditorOpened();
|
||||
settingsWindow.FindElementByName("Launch zones editor").Click();
|
||||
}
|
||||
|
||||
void OpenEditorByHotkey()
|
||||
{
|
||||
new Actions(session).KeyDown(OpenQA.Selenium.Keys.Command).SendKeys("`").KeyUp(OpenQA.Selenium.Keys.Command).Perform();
|
||||
TestEditorOpened();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
@@ -105,6 +120,7 @@ namespace PowerToysTests
|
||||
{
|
||||
RemoveSettingsFile();
|
||||
OpenEditorBySettingsButton();
|
||||
TestEditorOpened(true);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
@@ -121,6 +137,7 @@ namespace PowerToysTests
|
||||
|
||||
RemoveSettingsFolder();
|
||||
OpenEditorBySettingsButton();
|
||||
TestEditorOpened(true);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
@@ -128,6 +145,7 @@ namespace PowerToysTests
|
||||
{
|
||||
CreateEmptySettingsFile();
|
||||
OpenEditorBySettingsButton();
|
||||
TestEditorOpened(true);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
@@ -135,6 +153,7 @@ namespace PowerToysTests
|
||||
{
|
||||
CreateDefaultSettingsFile();
|
||||
OpenEditorBySettingsButton();
|
||||
TestEditorOpened();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
@@ -142,6 +161,7 @@ namespace PowerToysTests
|
||||
{
|
||||
CreateValidSettingsFile();
|
||||
OpenEditorBySettingsButton();
|
||||
TestEditorOpened();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
@@ -149,6 +169,7 @@ namespace PowerToysTests
|
||||
{
|
||||
CreateValidSettingsFileWithUtf8();
|
||||
OpenEditorBySettingsButton();
|
||||
TestEditorOpened();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
@@ -156,6 +177,7 @@ namespace PowerToysTests
|
||||
{
|
||||
CreateInvalidSettingsFile();
|
||||
OpenEditorBySettingsButton();
|
||||
TestEditorOpened(true);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
@@ -163,6 +185,7 @@ namespace PowerToysTests
|
||||
{
|
||||
CreateCroppedSettingsFile();
|
||||
OpenEditorBySettingsButton();
|
||||
TestEditorOpened(true);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
@@ -170,6 +193,7 @@ namespace PowerToysTests
|
||||
{
|
||||
RemoveSettingsFile();
|
||||
OpenEditorByHotkey();
|
||||
TestEditorOpened(true);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
@@ -185,6 +209,7 @@ namespace PowerToysTests
|
||||
*/
|
||||
RemoveSettingsFolder();
|
||||
OpenEditorByHotkey();
|
||||
TestEditorOpened(true);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
@@ -192,6 +217,7 @@ namespace PowerToysTests
|
||||
{
|
||||
CreateEmptySettingsFile();
|
||||
OpenEditorByHotkey();
|
||||
TestEditorOpened(true);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
@@ -199,6 +225,7 @@ namespace PowerToysTests
|
||||
{
|
||||
CreateDefaultSettingsFile();
|
||||
OpenEditorByHotkey();
|
||||
TestEditorOpened();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
@@ -206,6 +233,7 @@ namespace PowerToysTests
|
||||
{
|
||||
CreateValidSettingsFile();
|
||||
OpenEditorByHotkey();
|
||||
TestEditorOpened();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
@@ -213,6 +241,7 @@ namespace PowerToysTests
|
||||
{
|
||||
CreateValidSettingsFileWithUtf8();
|
||||
OpenEditorByHotkey();
|
||||
TestEditorOpened();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
@@ -220,6 +249,7 @@ namespace PowerToysTests
|
||||
{
|
||||
CreateInvalidSettingsFile();
|
||||
OpenEditorByHotkey();
|
||||
TestEditorOpened(true);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
@@ -227,14 +257,15 @@ namespace PowerToysTests
|
||||
{
|
||||
CreateCroppedSettingsFile();
|
||||
OpenEditorByHotkey();
|
||||
TestEditorOpened(true);
|
||||
}
|
||||
|
||||
[ClassInitialize]
|
||||
public static void ClassInitialize(TestContext context)
|
||||
{
|
||||
Setup(context, false);
|
||||
if (session == null)
|
||||
return;
|
||||
Setup(context);
|
||||
Assert.IsNotNull(session);
|
||||
EnableModules(false, true, false, false, false, false, false, false);
|
||||
|
||||
ResetDefaultFancyZonesSettings(true);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user