mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-01-01 18:06:25 +01:00
Compare commits
49 Commits
jay/DarkMo
...
yuleng/cmd
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b2db376b1f | ||
|
|
0a2e1f1424 | ||
|
|
0b739b45e6 | ||
|
|
f627fa823b | ||
|
|
11ca4a281f | ||
|
|
15aa63bf79 | ||
|
|
036fa957ab | ||
|
|
a9b510e2dc | ||
|
|
3206c0b073 | ||
|
|
82d031cf2a | ||
|
|
5c7c8c3009 | ||
|
|
64a48fda97 | ||
|
|
75cbd2d577 | ||
|
|
77b0a93fc0 | ||
|
|
dd47beabd8 | ||
|
|
29a8bbc40a | ||
|
|
35f7124756 | ||
|
|
074a00faa8 | ||
|
|
6607b60bd5 | ||
|
|
983591e4e0 | ||
|
|
0a2a3fea93 | ||
|
|
30d67ec078 | ||
|
|
4c87a78b1a | ||
|
|
f12d983025 | ||
|
|
369babc0f8 | ||
|
|
6834fa24af | ||
|
|
14f18f4b95 | ||
|
|
4bf2342a09 | ||
|
|
20243c4b99 | ||
|
|
a19127bf49 | ||
|
|
aeaa5297f9 | ||
|
|
cd45bad9ce | ||
|
|
2ae636a860 | ||
|
|
3bf8a63dd8 | ||
|
|
11b6e15869 | ||
|
|
f59063d285 | ||
|
|
83703d2cf2 | ||
|
|
205ca7645e | ||
|
|
2e0d5d0786 | ||
|
|
de1d1b4020 | ||
|
|
2c01dcd5af | ||
|
|
599a927d8a | ||
|
|
803d65cf98 | ||
|
|
3fce8697f3 | ||
|
|
925d5b030e | ||
|
|
37256aca56 | ||
|
|
f9c1fd8d62 | ||
|
|
04aa0a07ed | ||
|
|
d450e06bf9 |
@@ -33,10 +33,11 @@ namespace Microsoft.PowerToys.UITest
|
||||
private readonly PowerToysModule scope;
|
||||
private readonly WindowSize size;
|
||||
private readonly string[]? commandLineArgs;
|
||||
private readonly bool hideAllWindowBeforeStart;
|
||||
private SessionHelper? sessionHelper;
|
||||
private System.Threading.Timer? screenshotTimer;
|
||||
|
||||
public UITestBase(PowerToysModule scope = PowerToysModule.PowerToysSettings, WindowSize size = WindowSize.UnSpecified, string[]? commandLineArgs = null)
|
||||
public UITestBase(PowerToysModule scope = PowerToysModule.PowerToysSettings, WindowSize size = WindowSize.UnSpecified, string[]? commandLineArgs = null, bool hideAllWindowBeforeStart = false)
|
||||
{
|
||||
this.IsInPipeline = EnvironmentConfig.IsInPipeline;
|
||||
Console.WriteLine($"Running tests on platform: {EnvironmentConfig.Platform}");
|
||||
@@ -52,6 +53,7 @@ namespace Microsoft.PowerToys.UITest
|
||||
this.scope = scope;
|
||||
this.size = size;
|
||||
this.commandLineArgs = commandLineArgs;
|
||||
this.hideAllWindowBeforeStart = hideAllWindowBeforeStart;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -74,6 +76,12 @@ namespace Microsoft.PowerToys.UITest
|
||||
System.Windows.Forms.SendKeys.SendWait("{ESC}");
|
||||
}
|
||||
|
||||
if (hideAllWindowBeforeStart)
|
||||
{
|
||||
KeyboardHelper.SendKeys([Key.Win, Key.M]);
|
||||
Task.Delay(2000).Wait(); // Wait for a second to ensure all windows are minimized
|
||||
}
|
||||
|
||||
this.sessionHelper = new SessionHelper(scope, commandLineArgs).Init();
|
||||
this.Session = new Session(this.sessionHelper.GetRoot(), this.sessionHelper.GetDriver(), scope, size);
|
||||
}
|
||||
@@ -578,13 +586,31 @@ namespace Microsoft.PowerToys.UITest
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Moves the mouse cursor to the specified screen coordinates.
|
||||
/// </summary>
|
||||
/// <param name="x">The new x-coordinate of the cursor.</param>
|
||||
/// <param name="y">The new y-coordinate of the cursor.</param
|
||||
/// Moves the mouse cursor to the specified screen coordinates.
|
||||
/// </summary>
|
||||
/// <param name="x">The new x-coordinate of the cursor.</param>
|
||||
/// <param name="y">The new y-coordinate of the cursor.</param>
|
||||
public void MoveMouseTo(int x, int y)
|
||||
{
|
||||
this.Session.MoveMouseTo(x, y);
|
||||
this.Session.MoveMouseTo(x, y);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Moves the mouse cursor to the center of the screen.
|
||||
/// </summary>
|
||||
public void MoveMouseToCenter()
|
||||
{
|
||||
var (centerX, centerY) = this.GetScreenCenter();
|
||||
this.MoveMouseTo(centerX, centerY);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Moves the mouse cursor to the center of the screen and performs a left click.
|
||||
/// </summary>
|
||||
public void FocusOnCenter()
|
||||
{
|
||||
this.MoveMouseToCenter();
|
||||
this.Session.PerformMouseAction(MouseActionType.LeftClick);
|
||||
}
|
||||
|
||||
protected void AddScreenShotsToTestResultsDirectory()
|
||||
|
||||
264
src/modules/cmdpal/Tests/Microsoft.CmdPal.UITests/AppsTests.cs
Normal file
264
src/modules/cmdpal/Tests/Microsoft.CmdPal.UITests/AppsTests.cs
Normal file
@@ -0,0 +1,264 @@
|
||||
// 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;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml.Linq;
|
||||
using Microsoft.PowerToys.UITest;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
|
||||
namespace Microsoft.CmdPal.UITests;
|
||||
|
||||
[TestClass]
|
||||
public class AppsTests : CommandPaletteTestBase
|
||||
{
|
||||
public void EnterAppsExtension()
|
||||
{
|
||||
SetSearchBox("All Apps");
|
||||
|
||||
var searchFileItem = this.Find<NavigationViewItem>("All Apps");
|
||||
Assert.AreEqual(searchFileItem.Name, "All Apps");
|
||||
searchFileItem.DoubleClick();
|
||||
}
|
||||
|
||||
public NavigationViewItem SearchAppByName(string name)
|
||||
{
|
||||
EnterAppsExtension();
|
||||
SetAppsExtensionSearchBox(name);
|
||||
var item = this.Find<NavigationViewItem>(name);
|
||||
Assert.IsNotNull(item, $"{name} app not found.");
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void OpenWin32AppTest()
|
||||
{
|
||||
const string appName = "Notepad";
|
||||
var notepadItem = SearchAppByName(appName);
|
||||
notepadItem.DoubleClick();
|
||||
|
||||
var commandPromptWindow = FindWindowsTerminalWindow();
|
||||
Assert.IsNotNull(commandPromptWindow, "Command Prompt window not found.");
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void OpenUWPAppTest()
|
||||
{
|
||||
const string appName = "Calculator";
|
||||
var calculatorItem = SearchAppByName(appName);
|
||||
calculatorItem.DoubleClick();
|
||||
|
||||
var calculatorWindow = this.Find<Window>("Calculator", global: true);
|
||||
Assert.IsNotNull(calculatorWindow, "Calculator window not found.");
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void ClickPrimaryButtonTest()
|
||||
{
|
||||
const string appName = "Notepad";
|
||||
var notepadItem = SearchAppByName(appName);
|
||||
notepadItem.Click();
|
||||
|
||||
var primaryButton = this.Find<Button>("Run");
|
||||
Assert.IsNotNull(primaryButton, "Primary button not found.");
|
||||
primaryButton.Click();
|
||||
var calculatorWindow = this.Find<Window>(By.ClassName("Notepad"), global: true, timeoutMS: 10000);
|
||||
Assert.IsNotNull(calculatorWindow, "Notepad window not found.");
|
||||
}
|
||||
|
||||
[STATestMethod]
|
||||
[TestMethod]
|
||||
public void ClickSecondaryButtonUWPAppTest()
|
||||
{
|
||||
const string appName = "Calculator";
|
||||
var calculatorItem = SearchAppByName(appName);
|
||||
|
||||
calculatorItem.Click();
|
||||
|
||||
var secondaryButton = this.Find<Button>("Copy path");
|
||||
Assert.IsNotNull(secondaryButton, "Secondary button not found.");
|
||||
secondaryButton.Click();
|
||||
|
||||
var clipboardContent = System.Windows.Forms.Clipboard.GetText();
|
||||
Assert.IsTrue(clipboardContent.Contains("Calculator"), $"Clipboard content does not contain the expected file name. clipboard: {clipboardContent}");
|
||||
}
|
||||
|
||||
/*
|
||||
[TestMethod]
|
||||
public void ClickSecondaryButtonWin32AppTest()
|
||||
{
|
||||
const string appName = "Registry Editor";
|
||||
var calculatorItem = SearchAppByName(appName);
|
||||
|
||||
calculatorItem.Click();
|
||||
|
||||
var secondaryButton = this.Find<Button>("Run as administrator");
|
||||
Assert.IsNotNull(secondaryButton, "Secondary button not found.");
|
||||
secondaryButton.Click();
|
||||
|
||||
UACConfirm();
|
||||
|
||||
var fileExplorerWindow = this.Find<Window>(By.ClassName("RegEdit_RegEdit"), global: true);
|
||||
Assert.IsNotNull(fileExplorerWindow, "Registry Editor window not found.");
|
||||
}*/
|
||||
|
||||
[TestMethod]
|
||||
public void OpenContextMenuTest()
|
||||
{
|
||||
const string appName = "Notepad";
|
||||
var notepadItem = SearchAppByName(appName);
|
||||
notepadItem.Click();
|
||||
OpenContextMenu();
|
||||
|
||||
var pinButton = this.Find<NavigationViewItem>("Pin");
|
||||
Assert.IsNotNull(pinButton);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void ContextMenuRunButtonTest()
|
||||
{
|
||||
const string appName = "Notepad";
|
||||
var notepadItem = SearchAppByName(appName);
|
||||
notepadItem.Click();
|
||||
OpenContextMenu();
|
||||
|
||||
var runButton = this.Find<NavigationViewItem>("Run");
|
||||
Assert.IsNotNull(runButton);
|
||||
runButton.Click();
|
||||
|
||||
var notepadWindow = this.Find<Window>(By.ClassName("Notepad"), global: true);
|
||||
Assert.IsNotNull(notepadWindow, "Notepad window not found.");
|
||||
}
|
||||
|
||||
/*
|
||||
[TestMethod]
|
||||
public void ContextMenuRunAsAdminButtonTest()
|
||||
{
|
||||
const string appName = "Notepad";
|
||||
var notepadItem = SearchAppByName(appName);
|
||||
notepadItem.Click();
|
||||
OpenContextMenu();
|
||||
|
||||
var runButton = this.Find<NavigationViewItem>("Run as administrator");
|
||||
Assert.IsNotNull(runButton);
|
||||
runButton.Click();
|
||||
|
||||
UACConfirm();
|
||||
|
||||
var notepadWindow = this.Find<Window>(By.ClassName("Notepad"), global: true);
|
||||
Assert.IsNotNull(notepadWindow, "Notepad window not found.");
|
||||
}*/
|
||||
|
||||
[STATestMethod]
|
||||
[TestMethod]
|
||||
public void ContextMenuCopyPathButtonTest()
|
||||
{
|
||||
const string appName = "Notepad";
|
||||
var notepadItem = SearchAppByName(appName);
|
||||
notepadItem.Click();
|
||||
OpenContextMenu();
|
||||
|
||||
var copyPathButton = this.Find<NavigationViewItem>("Copy path");
|
||||
Assert.IsNotNull(copyPathButton);
|
||||
copyPathButton.Click();
|
||||
|
||||
var clipboardContent = System.Windows.Forms.Clipboard.GetText();
|
||||
Assert.IsTrue(clipboardContent.Contains("Notepad"), $"Clipboard content does not contain the expected file name. clipboard: {clipboardContent}");
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void ContextMenuPinTest()
|
||||
{
|
||||
const string appName = "Notepad";
|
||||
var notepadItem = SearchAppByName(appName);
|
||||
notepadItem.Click();
|
||||
OpenContextMenu();
|
||||
|
||||
var pinButton = this.Find<NavigationViewItem>("Pin");
|
||||
Assert.IsNotNull(pinButton);
|
||||
pinButton.Click();
|
||||
|
||||
SetAppsExtensionSearchBox(string.Empty);
|
||||
var item = this.Find<NavigationViewItem>(appName);
|
||||
Assert.IsNotNull(item, $"{appName} app not found.");
|
||||
OpenContextMenu();
|
||||
var unPinButton = this.Find<NavigationViewItem>("Unpin");
|
||||
Assert.IsNotNull(unPinButton);
|
||||
unPinButton.Click();
|
||||
SetAppsExtensionSearchBox(string.Empty);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void ContextMenuOpenContainingFolderTest()
|
||||
{
|
||||
const string appName = "Calculator";
|
||||
var notepadItem = SearchAppByName(appName);
|
||||
notepadItem.Click();
|
||||
OpenContextMenu();
|
||||
|
||||
var openContainingFolderButton = this.Find<NavigationViewItem>("Open containing folder");
|
||||
Assert.IsNotNull(openContainingFolderButton);
|
||||
openContainingFolderButton.Click();
|
||||
|
||||
var fileExplorerWindow = FindFileExplorerWindow();
|
||||
|
||||
Assert.IsNotNull(fileExplorerWindow);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void ContextMenuOpenPathInConsoleTest()
|
||||
{
|
||||
const string appName = "Notepad";
|
||||
var notepadItem = SearchAppByName(appName);
|
||||
notepadItem.Click();
|
||||
OpenContextMenu();
|
||||
|
||||
var openInConsoleButton = this.Find<NavigationViewItem>("Open path in console");
|
||||
Assert.IsNotNull(openInConsoleButton);
|
||||
openInConsoleButton.Click();
|
||||
|
||||
Task.Delay(2000).Wait(); // Wait for the console to open
|
||||
|
||||
var commandPromptWindow = FindWindowsTerminalWindow();
|
||||
Assert.IsNotNull(commandPromptWindow, "Command Prompt window not found.");
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void ContextMenuOpenLocationTest()
|
||||
{
|
||||
const string appName = "Command Prompt";
|
||||
var notepadItem = SearchAppByName(appName);
|
||||
notepadItem.Click();
|
||||
OpenContextMenu();
|
||||
var openLocationButton = this.Find<NavigationViewItem>("Open location");
|
||||
Assert.IsNotNull(openLocationButton, "Open location button not found.");
|
||||
openLocationButton.Click();
|
||||
var fileExplorerWindow = FindFileExplorerWindow();
|
||||
Assert.IsNotNull(fileExplorerWindow, "File Explorer window not found.");
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void ContextMenuSearchTest()
|
||||
{
|
||||
const string appName = "Command Prompt";
|
||||
var notepadItem = SearchAppByName(appName);
|
||||
notepadItem.Click();
|
||||
OpenContextMenu();
|
||||
|
||||
var contextMenuSearchBox = this.Find<TextBox>("Search commands...");
|
||||
Assert.IsNotNull(contextMenuSearchBox, "Context menu search box not found.");
|
||||
|
||||
Assert.AreEqual(contextMenuSearchBox.SetText("Open location", true).Text, "Open location");
|
||||
var openLocationButton = this.Find<NavigationViewItem>("Open location");
|
||||
Assert.IsNotNull(openLocationButton, "Open location button not found.");
|
||||
openLocationButton.Click();
|
||||
|
||||
var fileExplore = FindFileExplorerWindow();
|
||||
Assert.IsNotNull(fileExplore, "File Explorer window not found.");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,167 @@
|
||||
// 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;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.PowerToys.UITest;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
|
||||
namespace Microsoft.CmdPal.UITests;
|
||||
|
||||
[TestClass]
|
||||
public class CalculatorTests : CommandPaletteTestBase
|
||||
{
|
||||
public CalculatorTests()
|
||||
: base()
|
||||
{
|
||||
}
|
||||
|
||||
public void EnterCalculatorExtension()
|
||||
{
|
||||
SetSearchBox("Calculator");
|
||||
var calculatorItem = this.Find<NavigationViewItem>("Calculator");
|
||||
Assert.AreEqual(calculatorItem.Name, "Calculator");
|
||||
calculatorItem.DoubleClick();
|
||||
}
|
||||
|
||||
private string ConvertResult(string originalResult, int originalBase, int convertToBase)
|
||||
{
|
||||
Assert.IsNotEmpty(originalResult, "Original result cannot be empty.");
|
||||
Assert.IsTrue(originalBase is 2 or 10 or 16, "Original base must be one of the following: 2, 8, 10, or 16.");
|
||||
Assert.IsTrue(convertToBase is 2 or 10 or 16, "Convert to base must be one of the following: 2, 8, 10, or 16.");
|
||||
|
||||
var originalDecimal = Convert.ToInt32(originalResult, originalBase);
|
||||
|
||||
// support base two, decimal, hexadecimal, and octal
|
||||
return convertToBase switch
|
||||
{
|
||||
2 => $"0b{Convert.ToString(originalDecimal, 2)}",
|
||||
10 => Convert.ToString(originalDecimal, 10),
|
||||
16 => $"0x{Convert.ToString(originalDecimal, 16).ToUpper(System.Globalization.CultureInfo.CurrentCulture)}",
|
||||
_ => throw new ArgumentOutOfRangeException(nameof(convertToBase), "Unsupported base conversion"),
|
||||
};
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[DataRow("2+2", "4")]
|
||||
[DataRow("2*3", "6")]
|
||||
[DataRow("2^3", "8")]
|
||||
public void CalculatorBasicTests(string expression, string expectation)
|
||||
{
|
||||
EnterCalculatorExtension();
|
||||
SetCalculatorExtensionSearchBox(expression);
|
||||
var resultItem = this.Find<NavigationViewItem>(expectation);
|
||||
|
||||
Assert.IsNotNull(resultItem);
|
||||
Assert.AreEqual(resultItem.Name, expectation, $"Expected result '{expectation}' not found for expression '{expression}'.");
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[DataRow("2+2", "4")]
|
||||
public void CalculatorResultDoubleClickTests(string expression, string expectation)
|
||||
{
|
||||
EnterCalculatorExtension();
|
||||
SetCalculatorExtensionSearchBox(expression);
|
||||
var resultItem = this.Find<NavigationViewItem>(expectation);
|
||||
|
||||
Assert.IsNotNull(resultItem);
|
||||
Assert.AreEqual(resultItem.Name, expectation, $"Expected result '{expectation}' not found for expression '{expression}'.");
|
||||
|
||||
resultItem.DoubleClick();
|
||||
var resultItems = this.FindAll<NavigationViewItem>(expectation);
|
||||
Assert.AreEqual(2, resultItems.Count, $"Expected exactly two result item for '{expectation}' after double-clicking, but found {resultItems.Count}.");
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[DataRow("2+2", "4")]
|
||||
public void CalculatorPrimaryButtonTests(string expression, string expectation)
|
||||
{
|
||||
EnterCalculatorExtension();
|
||||
SetCalculatorExtensionSearchBox(expression);
|
||||
var resultItem = this.Find<NavigationViewItem>(expectation);
|
||||
|
||||
Assert.IsNotNull(resultItem);
|
||||
Assert.AreEqual(resultItem.Name, expectation, $"Expected result '{expectation}' not found for expression '{expression}'.");
|
||||
|
||||
var primaryButton = this.Find<Button>("Save");
|
||||
primaryButton.Click();
|
||||
var resultItems = this.FindAll<NavigationViewItem>(expectation);
|
||||
Assert.AreEqual(2, resultItems.Count, $"Expected exactly two result item for '{expectation}' after click primary button, but found {resultItems.Count}.");
|
||||
}
|
||||
|
||||
[STATestMethod]
|
||||
[TestMethod]
|
||||
[DataRow("2+2", "4")]
|
||||
public void CalculatorSecondaryButtonTests(string expression, string expectation)
|
||||
{
|
||||
EnterCalculatorExtension();
|
||||
SetCalculatorExtensionSearchBox(expression);
|
||||
var resultItem = this.Find<NavigationViewItem>(expectation);
|
||||
|
||||
Assert.IsNotNull(resultItem);
|
||||
Assert.AreEqual(resultItem.Name, expectation, $"Expected result '{expectation}' not found for expression '{expression}'.");
|
||||
|
||||
var secondaryButton = this.Find<Button>("Copy");
|
||||
secondaryButton.Click();
|
||||
|
||||
var clipboardContent = System.Windows.Forms.Clipboard.GetText();
|
||||
Assert.IsTrue(clipboardContent.Equals(expectation, StringComparison.Ordinal), $"Clipboard content does not equal the expected result. clipboard: {clipboardContent}");
|
||||
}
|
||||
|
||||
[STATestMethod]
|
||||
[TestMethod]
|
||||
[DataRow("2+2", "4")]
|
||||
public void CalculatorContextMenuSaveTests(string expression, string expectation)
|
||||
{
|
||||
EnterCalculatorExtension();
|
||||
SetCalculatorExtensionSearchBox(expression);
|
||||
var resultItem = this.Find<NavigationViewItem>(expectation);
|
||||
|
||||
Assert.IsNotNull(resultItem);
|
||||
Assert.AreEqual(resultItem.Name, expectation, $"Expected result '{expectation}' not found for expression '{expression}'.");
|
||||
|
||||
OpenContextMenu();
|
||||
|
||||
var saveItem = this.Find<NavigationViewItem>("Save");
|
||||
saveItem.Click();
|
||||
|
||||
var clipboardContent = System.Windows.Forms.Clipboard.GetText();
|
||||
Assert.IsTrue(clipboardContent.Equals(expectation, StringComparison.Ordinal), $"Clipboard content does not equal the expected result. clipboard: {clipboardContent}");
|
||||
}
|
||||
|
||||
[STATestMethod]
|
||||
[TestMethod]
|
||||
[DataRow("2+2", "4", 10)]
|
||||
[DataRow("0b10 * 0b10", "4", 2)]
|
||||
[DataRow("0xa * 0xa", "100", 16)]
|
||||
public void CalculatorContextMenuBaseConvertTests(string expression, string expectation, int originalBase)
|
||||
{
|
||||
EnterCalculatorExtension();
|
||||
SetCalculatorExtensionSearchBox(expression);
|
||||
var resultItem = this.Find<NavigationViewItem>(expectation);
|
||||
|
||||
Assert.IsNotNull(resultItem);
|
||||
Assert.AreEqual(resultItem.Name, expectation, $"Expected result '{expectation}' not found for expression '{expression}'.");
|
||||
|
||||
OpenContextMenu();
|
||||
|
||||
var testBaseList = new List<int> { 2, 10, 16 };
|
||||
foreach (var convertToBase in testBaseList)
|
||||
{
|
||||
var convertedResult = ConvertResult(expectation, 10, convertToBase);
|
||||
var convertedItem = this.Find<NavigationViewItem>(convertedResult);
|
||||
Assert.IsNotNull(convertedItem, $"Convert to base {convertToBase} item not found.");
|
||||
}
|
||||
|
||||
var binaryResult = ConvertResult(expectation, 10, 2);
|
||||
var binaryItem = this.Find<NavigationViewItem>(binaryResult);
|
||||
binaryItem.Click();
|
||||
|
||||
var clipboardContent = System.Windows.Forms.Clipboard.GetText();
|
||||
Assert.IsTrue(clipboardContent.Equals(binaryResult, StringComparison.Ordinal), $"Clipboard content does not equal the expected result. clipboard: {clipboardContent}");
|
||||
}
|
||||
}
|
||||
@@ -12,10 +12,11 @@ using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
|
||||
namespace Microsoft.CmdPal.UITests;
|
||||
|
||||
[TestClass]
|
||||
public class CommandPaletteTestBase : UITestBase
|
||||
{
|
||||
public CommandPaletteTestBase()
|
||||
: base(PowerToysModule.CommandPalette)
|
||||
: base(PowerToysModule.CommandPalette, hideAllWindowBeforeStart: true)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -39,6 +40,21 @@ public class CommandPaletteTestBase : UITestBase
|
||||
Assert.AreEqual(this.Find<TextBox>("Search values or type a custom time stamp...").SetText(text, true).Text, text);
|
||||
}
|
||||
|
||||
protected void SetAppsExtensionSearchBox(string text)
|
||||
{
|
||||
Assert.AreEqual(this.Find<TextBox>("Search installed apps...").SetText(text, true).Text, text);
|
||||
}
|
||||
|
||||
protected void SetWindowsTerminalExtensionSearchBox(string text)
|
||||
{
|
||||
Assert.AreEqual(this.Find<TextBox>("Type here to search...").SetText(text, true).Text, text);
|
||||
}
|
||||
|
||||
protected void SetWindowsSettingsExtensionSearchBox(string text)
|
||||
{
|
||||
Assert.AreEqual(this.Find<TextBox>("Type here to search...").SetText(text, true).Text, text);
|
||||
}
|
||||
|
||||
protected void OpenContextMenu()
|
||||
{
|
||||
var contextMenuButton = this.Find<Button>("More");
|
||||
@@ -46,6 +62,24 @@ public class CommandPaletteTestBase : UITestBase
|
||||
contextMenuButton.Click();
|
||||
}
|
||||
|
||||
protected Window FindFileExplorerWindow()
|
||||
{
|
||||
var fileExplorerWindow = this.Find<Window>(By.ClassName("CabinetWClass"), global: true, timeoutMS: 5000);
|
||||
return fileExplorerWindow;
|
||||
}
|
||||
|
||||
protected Window FindWindowsTerminalWindow()
|
||||
{
|
||||
var terminalWindow = this.Find<Window>(By.ClassName("CASCADIA_HOSTING_WINDOW_CLASS"), global: true, timeoutMS: 5000);
|
||||
return terminalWindow;
|
||||
}
|
||||
|
||||
protected Window FindWindowsSettingsWindow()
|
||||
{
|
||||
var settingsWindow = this.Find<Window>("Settings", global: true, timeoutMS: 5000);
|
||||
return settingsWindow;
|
||||
}
|
||||
|
||||
protected void FindDefaultAppDialogAndClickButton()
|
||||
{
|
||||
try
|
||||
|
||||
@@ -114,9 +114,10 @@ public class IndexerTests : CommandPaletteTestBase
|
||||
Assert.IsNotNull(openButton);
|
||||
|
||||
openButton.Click();
|
||||
var fileExplorer = FindExplorerWindow(TestFolderName, global: true);
|
||||
|
||||
Assert.IsNotNull(fileExplorer);
|
||||
var fileExplorerWindow = FindFileExplorerWindow();
|
||||
|
||||
Assert.IsNotNull(fileExplorerWindow);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
@@ -129,9 +130,9 @@ public class IndexerTests : CommandPaletteTestBase
|
||||
Assert.IsNotNull(searchItem);
|
||||
searchItem.DoubleClick();
|
||||
|
||||
var fileExplorer = FindExplorerWindow(TestFolderName, global: true);
|
||||
var fileExplorerWindow = FindFileExplorerWindow();
|
||||
|
||||
Assert.IsNotNull(fileExplorer);
|
||||
Assert.IsNotNull(fileExplorerWindow);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
@@ -188,9 +189,9 @@ public class IndexerTests : CommandPaletteTestBase
|
||||
Assert.IsNotNull(showInFolderButton);
|
||||
showInFolderButton.Click();
|
||||
|
||||
var fileExplorer = FindExplorerWindow(TestFolderName, global: true, timeoutMS: 20000);
|
||||
var fileExplorerWindow = FindFileExplorerWindow();
|
||||
|
||||
Assert.IsNotNull(fileExplorer);
|
||||
Assert.IsNotNull(fileExplorerWindow);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
@@ -208,8 +209,8 @@ public class IndexerTests : CommandPaletteTestBase
|
||||
Assert.IsNotNull(copyPathButton);
|
||||
copyPathButton.Click();
|
||||
|
||||
var textItem = FindByPartialName("C:\\Windows\\system32\\cmd.exe", global: true);
|
||||
Assert.IsNotNull(textItem, "The console did not open with the expected path.");
|
||||
var terminalWindow = FindWindowsTerminalWindow();
|
||||
Assert.IsNotNull(terminalWindow, "The console did not open with the expected path.");
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
|
||||
@@ -0,0 +1,76 @@
|
||||
// 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;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.PowerToys.UITest;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using Windows.Graphics;
|
||||
|
||||
namespace Microsoft.CmdPal.UITests;
|
||||
|
||||
public class WindowsSettingsTests : CommandPaletteTestBase
|
||||
{
|
||||
public void EnterWindowsSettingsExtension()
|
||||
{
|
||||
SetSearchBox("Windows Settings");
|
||||
var searchFileItem = this.Find<NavigationViewItem>("Windows Settings");
|
||||
Assert.AreEqual(searchFileItem.Name, "Windows Settings");
|
||||
searchFileItem.DoubleClick();
|
||||
}
|
||||
|
||||
public NavigationViewItem SearchWindowsSettingsByName(string name)
|
||||
{
|
||||
EnterWindowsSettingsExtension();
|
||||
SetWindowsSettingsExtensionSearchBox(name);
|
||||
var item = this.Find<NavigationViewItem>(name);
|
||||
Assert.IsNotNull(item, $"{name} setting not found.");
|
||||
return item;
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void OpenDisplaySettingsTest()
|
||||
{
|
||||
const string settingName = "Display";
|
||||
var displaySettingItem = SearchWindowsSettingsByName(settingName);
|
||||
displaySettingItem.DoubleClick();
|
||||
|
||||
var settings = FindWindowsSettingsWindow();
|
||||
Assert.IsNotNull(settings, "Display settings window not found.");
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void OpenDisplaySettingsByPrimaryButtonTest()
|
||||
{
|
||||
const string settingName = "Display";
|
||||
var displaySettingItem = SearchWindowsSettingsByName(settingName);
|
||||
displaySettingItem.Click();
|
||||
|
||||
var primaryButton = this.Find<Button>("Open Settings");
|
||||
Assert.IsNotNull(primaryButton, "Primary button not found.");
|
||||
primaryButton.Click();
|
||||
|
||||
var settings = FindWindowsSettingsWindow();
|
||||
Assert.IsNotNull(settings, "Display settings window not found.");
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[STATestMethod]
|
||||
public void OpenDisplaySettingsSecondaryButtonTest()
|
||||
{
|
||||
const string settingName = "Display";
|
||||
var displaySettingItem = SearchWindowsSettingsByName(settingName);
|
||||
displaySettingItem.Click();
|
||||
|
||||
var secondaryButton = this.Find<Button>("Copy command");
|
||||
Assert.IsNotNull(secondaryButton, "Secondary button not found.");
|
||||
secondaryButton.Click();
|
||||
|
||||
var clipboardContent = System.Windows.Forms.Clipboard.GetText();
|
||||
Assert.IsTrue(clipboardContent.Contains("ms - settings:easeofaccess - display"), $"Clipboard content does not contain the expected command. clipboard: {clipboardContent}");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
// 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;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.PowerToys.UITest;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
|
||||
namespace Microsoft.CmdPal.UITests;
|
||||
|
||||
[TestClass]
|
||||
public class WindowsTerminalTests : CommandPaletteTestBase
|
||||
{
|
||||
public void EnterWindowsTerminalExtension()
|
||||
{
|
||||
SetSearchBox("Open Windows Terminal Profiles");
|
||||
|
||||
var searchFileItem = this.Find<NavigationViewItem>("Open Windows Terminal Profiles");
|
||||
Assert.AreEqual(searchFileItem.Name, "Open Windows Terminal Profiles");
|
||||
searchFileItem.DoubleClick();
|
||||
}
|
||||
|
||||
public NavigationViewItem SearchTerminalProfileName(string name)
|
||||
{
|
||||
EnterWindowsTerminalExtension();
|
||||
SetWindowsTerminalExtensionSearchBox(name);
|
||||
var item = this.Find<NavigationViewItem>(name);
|
||||
Assert.IsNotNull(item, $"{name} profile not found.");
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void OpenCommandPromptTest()
|
||||
{
|
||||
const string profileName = "Command Prompt";
|
||||
var terminalProfileItem = SearchTerminalProfileName(profileName);
|
||||
terminalProfileItem.DoubleClick();
|
||||
var commandPromptWindow = FindWindowsTerminalWindow();
|
||||
Assert.IsNotNull(commandPromptWindow, "Command Prompt window not found.");
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void OpenCommandPromptByPrimaryButtonTest()
|
||||
{
|
||||
const string profileName = "Command Prompt";
|
||||
var terminalProfileItem = SearchTerminalProfileName(profileName);
|
||||
terminalProfileItem.Click();
|
||||
|
||||
var primaryButton = this.Find<Button>("Launch profile");
|
||||
Assert.IsNotNull(primaryButton, "Primary button not found.");
|
||||
primaryButton.Click();
|
||||
|
||||
var commandPromptWindow = FindWindowsTerminalWindow();
|
||||
Assert.IsNotNull(commandPromptWindow, "Command Prompt window not found.");
|
||||
}
|
||||
|
||||
/*
|
||||
[TestMethod]
|
||||
public void OpenCommandPromptBySecondaryButtonTest()
|
||||
{
|
||||
const string profileName = "Command Prompt";
|
||||
var terminalProfileItem = SearchTerminalProfileName(profileName);
|
||||
terminalProfileItem.Click();
|
||||
|
||||
var secondaryButton = this.Find<Button>("Launch profile as administrator");
|
||||
Assert.IsNotNull(secondaryButton, "Secondary button not found.");
|
||||
secondaryButton.Click();
|
||||
|
||||
UACConfirm();
|
||||
|
||||
var commandPromptWindow = FindWindowsTerminalWindow();
|
||||
Assert.IsNotNull(commandPromptWindow, "Command Prompt window not found.");
|
||||
}*/
|
||||
|
||||
[TestMethod]
|
||||
public void OpenDeveloperCommandPromptTest()
|
||||
{
|
||||
const string profileName = "Developer Command Prompt for VS 2022";
|
||||
var terminalProfileItem = SearchTerminalProfileName(profileName);
|
||||
terminalProfileItem.DoubleClick();
|
||||
var commandPromptWindow = FindWindowsTerminalWindow();
|
||||
Assert.IsNotNull(commandPromptWindow, "Command Prompt window not found.");
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void OpenGitBashTest()
|
||||
{
|
||||
const string profileName = "Git Bash";
|
||||
var terminalProfileItem = SearchTerminalProfileName(profileName);
|
||||
terminalProfileItem.DoubleClick();
|
||||
var commandPromptWindow = FindWindowsTerminalWindow();
|
||||
Assert.IsNotNull(commandPromptWindow, "Command Prompt window not found.");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user