Skip to content

Commit

Permalink
fix mergeing
Browse files Browse the repository at this point in the history
  • Loading branch information
Zhaopeng Wang (from Dev Box) committed Feb 14, 2025
2 parents a5bb9a1 + 8e542b0 commit d934628
Show file tree
Hide file tree
Showing 10 changed files with 144 additions and 94 deletions.
15 changes: 15 additions & 0 deletions PowerToys.sln
Original file line number Diff line number Diff line change
Expand Up @@ -638,6 +638,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ZoomItSettingsInterop", "sr
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UITestAutomation", "src\common\UITestAutomation\UITestAutomation.csproj", "{A558C25D-2007-498E-8B6F-43405AFAE9E2}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "KeyboardManagerUITests", "src\modules\keyboardmanager\KeyboardManagerUITests\KeyboardManagerUITests.csproj", "{ED60B723-D24C-4D33-A6F0-053B43FB422A}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|ARM64 = Debug|ARM64
Expand Down Expand Up @@ -2848,6 +2850,18 @@ Global
{A558C25D-2007-498E-8B6F-43405AFAE9E2}.Release|x64.Build.0 = Release|x64
{A558C25D-2007-498E-8B6F-43405AFAE9E2}.Release|x86.ActiveCfg = Release|x64
{A558C25D-2007-498E-8B6F-43405AFAE9E2}.Release|x86.Build.0 = Release|x64
{ED60B723-D24C-4D33-A6F0-053B43FB422A}.Debug|ARM64.ActiveCfg = Debug|ARM64
{ED60B723-D24C-4D33-A6F0-053B43FB422A}.Debug|ARM64.Build.0 = Debug|ARM64
{ED60B723-D24C-4D33-A6F0-053B43FB422A}.Debug|x64.ActiveCfg = Debug|x64
{ED60B723-D24C-4D33-A6F0-053B43FB422A}.Debug|x64.Build.0 = Debug|x64
{ED60B723-D24C-4D33-A6F0-053B43FB422A}.Debug|x86.ActiveCfg = Debug|x64
{ED60B723-D24C-4D33-A6F0-053B43FB422A}.Debug|x86.Build.0 = Debug|x64
{ED60B723-D24C-4D33-A6F0-053B43FB422A}.Release|ARM64.ActiveCfg = Release|ARM64
{ED60B723-D24C-4D33-A6F0-053B43FB422A}.Release|ARM64.Build.0 = Release|ARM64
{ED60B723-D24C-4D33-A6F0-053B43FB422A}.Release|x64.ActiveCfg = Release|x64
{ED60B723-D24C-4D33-A6F0-053B43FB422A}.Release|x64.Build.0 = Release|x64
{ED60B723-D24C-4D33-A6F0-053B43FB422A}.Release|x86.ActiveCfg = Release|x64
{ED60B723-D24C-4D33-A6F0-053B43FB422A}.Release|x86.Build.0 = Release|x64
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -3084,6 +3098,7 @@ Global
{E4585179-2AC1-4D5F-A3FF-CFC5392F694C} = {DD6E12FE-5509-4ABC-ACC2-3D6DC98A238C}
{CA7D8106-30B9-4AEC-9D05-B69B31B8C461} = {DD6E12FE-5509-4ABC-ACC2-3D6DC98A238C}
{A558C25D-2007-498E-8B6F-43405AFAE9E2} = {1AFB6476-670D-4E80-A464-657E01DFF482}
{ED60B723-D24C-4D33-A6F0-053B43FB422A} = {38BDB927-829B-4C65-9CD9-93FB05D66D65}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {C3A2F9D1-7930-4EF4-A6FC-7EE0A99821D0}
Expand Down
4 changes: 1 addition & 3 deletions src/common/UITestAutomation/Element/Button.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,14 @@

namespace Microsoft.PowerToys.UITest
{
// Class representing a button element in the application
public class Button : Element
{
// Constructor to initialize the button
public Button()
: base()
{
}

// Method to get the type of the button
// Get Button Type
public string GetButtonType()
{
Assert.IsNotNull(WindowsElement, "WindowsElement should not be null");
Expand Down
12 changes: 2 additions & 10 deletions src/common/UITestAutomation/Element/By.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,38 +7,30 @@

namespace Microsoft.PowerToys.UITest
{
// This class is a wrapper around OpenQA.Selenium.By to provide a more user-friendly API.
// This class is a wrapper around OpenQA.Selenium.By
#pragma warning disable SA1649 // File name should match first type name
public class By
{
// The OpenQA.Selenium.By object that this class wraps.
private readonly OpenQA.Selenium.By by;

// Private constructor to prevent instantiation of this class from outside.
private By(OpenQA.Selenium.By by)
{
this.by = by;
}

// Factory method to create a By object using the element's name.
// Factory methods to create a By object
public static By Name(string name) => new By(OpenQA.Selenium.By.Name(name));

// Factory method to create a By object using the element's ID.
public static By Id(string id) => new By(OpenQA.Selenium.By.Id(id));

// Factory method to create a By object using an XPath expression.
public static By XPath(string xpath) => new By(OpenQA.Selenium.By.XPath(xpath));

// Factory method to create a By object using a CSS selector.
public static By CssSelector(string cssSelector) => new By(OpenQA.Selenium.By.CssSelector(cssSelector));

// Factory method to create a By object using the link text.
public static By LinkText(string linkText) => new By(OpenQA.Selenium.By.LinkText(linkText));

// Factory method to create a By object using the tag name.
public static By TagName(string tagName) => new By(OpenQA.Selenium.By.TagName(tagName));

// Method to convert this By object to an OpenQA.Selenium.By object.
public OpenQA.Selenium.By ToSeleniumBy() => by;
}
}
63 changes: 27 additions & 36 deletions src/common/UITestAutomation/Element/Element.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,89 +18,80 @@

namespace Microsoft.PowerToys.UITest
{
// Class representing a UI element in the application
// The basic class for all UI elements
public class Element
{
// Property to hold the Windows element
public WindowsElement? WindowsElement { get; set; }

// Property to hold the Windows driver
private WindowsDriver<WindowsElement>? driver;

// Constructor to initialize the element
public Element() => WindowsElement = null;

// Method to set the Windows element
internal void SetWindowsElement(WindowsElement windowsElement) => WindowsElement = windowsElement;

// Method to set the session driver
internal void SetSession(WindowsDriver<WindowsElement> driver) => this.driver = driver;

// Method to get the name attribute of the element
// Get the name of the element
public string GetName() => GetAttribute("Name");

// Method to get the text attribute of the element
// Get the text of the element
public string GetText() => GetAttribute("Value");

// Method to get the automation ID of the element
// Get the automation ID of the element
public string GetAutomationId() => GetAttribute("AutomationId");

// Method to get the class name of the element
// Get the class name of the element
public string GetClassName() => GetAttribute("ClassName");

// Method to get the help text of the element
// Get the help text of the element
public string GetHelpText() => GetAttribute("HelpText");

// Method to check if the element is enabled
public bool IsEnable() => GetAttribute("IsEnabled") == "True";
// Check if the element is enabled
public bool IsEnabled() => GetAttribute("IsEnabled") == "True";

// Method to check if the element is selected
// Check if the element is selected
public bool IsSelected() => GetAttribute("IsSelected") == "True";

// Method to click the element
// Click the element
public void Click() => PerformAction(actions => actions.Click());

// Method to right-click the element
// Right click the element
public void RightClick() => PerformAction(actions => actions.ContextClick());

// Method to check if a specific attribute matches a value
public bool CheckAttribute(string attributeKey, string attributeValue) => GetAttribute(attributeKey) == attributeValue;
// Get an attribute of the element
private string GetAttribute(string attributeName)
{
Assert.IsNotNull(WindowsElement, "WindowsElement should not be null");
return WindowsElement?.GetAttribute(attributeName) ?? string.Empty;
}

// Method to find an element by its name
public T FindElementByName<T>(string name, int timeoutInMilliseconds = 3000)
// Find element by Name
public T FindElementByName<T>(string name, int timeoutMS = 3000)
where T : Element, new()
{
Assert.IsNotNull(WindowsElement, "WindowsElement is null");
return FindElementHelper.FindElement<T, AppiumWebElement>(() => WindowsElement.FindElementByName(name), timeoutInMilliseconds, driver);
return FindElementHelper.FindElement<T, AppiumWebElement>(() => WindowsElement.FindElementByName(name), timeoutMS, driver);
}

// Method to find an element by its accessibility ID
public T? FindElementByAccessibilityId<T>(string name, int timeoutInMilliseconds = 3000)
// Find element by AccessibilityId
public T? FindElementByAccessibilityId<T>(string name, int timeoutMS = 3000)
where T : Element, new()
{
Assert.IsNotNull(WindowsElement, "WindowsElement is null");
return FindElementHelper.FindElement<T, AppiumWebElement>(() => WindowsElement.FindElementByAccessibilityId(name), timeoutInMilliseconds, driver);
return FindElementHelper.FindElement<T, AppiumWebElement>(() => WindowsElement.FindElementByAccessibilityId(name), timeoutMS, driver);
}

// Method to find multiple elements by their name
public ReadOnlyCollection<T>? FindElementsByName<T>(string name, int timeoutInMilliseconds = 3000)
// Find elements by name
public ReadOnlyCollection<T>? FindElementsByName<T>(string name, int timeoutMS = 3000)
where T : Element, new()
{
Assert.IsNotNull(WindowsElement, "WindowsElement is null");
return FindElementHelper.FindElements<T, AppiumWebElement>(() => WindowsElement.FindElementsByName(name), timeoutInMilliseconds, driver);
return FindElementHelper.FindElements<T, AppiumWebElement>(() => WindowsElement.FindElementsByName(name), timeoutMS, driver);
}

// Method to take a screenshot of the element
public Screenshot? GetScreenShot() => WindowsElement?.GetScreenshot();

// Helper method to get an attribute of the element
private string GetAttribute(string attributeName)
{
Assert.IsNotNull(WindowsElement, $"{attributeName} should not be null");
return WindowsElement?.GetAttribute(attributeName) ?? string.Empty;
}

// Helper method to perform an action on the element
// Simulate manual operation
private void PerformAction(Action<Actions> action)
{
var element = WindowsElement;
Expand Down
15 changes: 10 additions & 5 deletions src/common/UITestAutomation/Element/Window.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,34 +11,39 @@

namespace Microsoft.PowerToys.UITest
{
// Class representing a window in the application
public class Window : Element
{
// Class representing a window in the application
public Window()
: base()
{
}

// Method to maximize the window
// Click the Maximize button of the window
public Window Maximize()
{
FindElementByName<Button>("Maximize").Click();
return this;
}

// Method to restore the window to its original size
// Click the Restore button of the window
public Window Restore()
{
FindElementByName<Button>("Restore").Click();
return this;
}

// Method to minimize the window
// Click the Minimize button of the window
public Window Minimize()
{
FindElementByName<Button>("Minimize").Click();
return this;
}

// Click the Close button of the window
public Window Close()
{
FindElementByName<Button>("Close").Click();
return this;
}
}
}
10 changes: 2 additions & 8 deletions src/common/UITestAutomation/ModuleConfigData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,13 @@ public class ModuleConfigData

public static ModuleConfigData Instance => MInstance.Value;

// Dictionary to hold module window names
public Dictionary<PowerToysModuleWindow, ModuleWindowData> ModuleWindowName { get; }

// Dictionary to hold module paths
private Dictionary<PowerToysModule, string> ModulePath { get; }

// Private constructor to initialize module data
private ModuleConfigData()
{
// Module name and Window name
ModuleWindowName = new Dictionary<PowerToysModuleWindow, ModuleWindowData>
{
[PowerToysModuleWindow.PowerToysSettings] = new ModuleWindowData("PowerToys", "PowerToys Settings"),
Expand All @@ -53,31 +51,27 @@ private ModuleConfigData()
[PowerToysModuleWindow.Hosts] = new ModuleWindowData("Hosts", "Hosts File Editor"),
};

// Exe start path when scope is set to module
ModulePath = new Dictionary<PowerToysModule, string>
{
[PowerToysModule.FancyZone] = @"\..\..\..\PowerToys.FancyZones.exe",
[PowerToysModule.Hosts] = @"\..\..\..\WinUI3Apps\PowerToys.Hosts.exe",
};
}

// Method to get the path of a module
public string GetModulePath(PowerToysModule scope) => ModulePath[scope];

// Method to get the URL of the Windows Application Driver
public string GetWindowsApplicationDriverUrl() => WindowsApplicationDriverUrl;

// Method to get the window data of a module
public ModuleWindowData GetModuleWindowData(PowerToysModuleWindow scope) => ModuleWindowName[scope];
}

// Struct to hold module window data
public struct ModuleWindowData
{
public string ModuleName { get; set; }

public string WindowName { get; set; }

// Constructor to initialize module window data
public ModuleWindowData(string moduleName, string windowName)
{
ModuleName = moduleName;
Expand Down
26 changes: 11 additions & 15 deletions src/common/UITestAutomation/Session.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,51 +16,47 @@

namespace Microsoft.PowerToys.UITest
{
// Class representing a session for UI testing
// Wrap WinAppDriver and provide interfaces to users
public class Session
{
// Property to hold the root driver
private WindowsDriver<WindowsElement> Root { get; set; }

// Property to hold the Windows driver
private WindowsDriver<WindowsElement> WindowsDriver { get; set; }

// Importing user32.dll to set the foreground window
[DllImport("user32.dll")]
private static extern bool SetForegroundWindow(nint hWnd);

// Constructor to initialize the session with root and Windows driver
public Session(WindowsDriver<WindowsElement> root, WindowsDriver<WindowsElement> windowsDriver)
{
Root = root;
WindowsDriver = windowsDriver;
}

// Method to find an element by a given selector
public T FindElement<T>(By by, int timeoutInMilliseconds = 3000)
// Find element by selector
public T FindElement<T>(By by, int timeoutMS = 3000)
where T : Element, new()
{
Assert.IsNotNull(WindowsDriver, "WindowsElement is null");
return FindElementHelper.FindElement<T, WindowsElement>(() => WindowsDriver.FindElement(by.ToSeleniumBy()), timeoutInMilliseconds, WindowsDriver);
return FindElementHelper.FindElement<T, WindowsElement>(() => WindowsDriver.FindElement(by.ToSeleniumBy()), timeoutMS, WindowsDriver);
}

// Method to find an element by its name
public T FindElementByName<T>(string name, int timeoutInMilliseconds = 3000)
// Find element by name
public T FindElementByName<T>(string name, int timeoutMS = 3000)
where T : Element, new()
{
Assert.IsNotNull(WindowsDriver, "WindowsElement is null");
return FindElementHelper.FindElement<T, WindowsElement>(() => WindowsDriver.FindElementByName(name), timeoutInMilliseconds, WindowsDriver);
return FindElementHelper.FindElement<T, WindowsElement>(() => WindowsDriver.FindElementByName(name), timeoutMS, WindowsDriver);
}

// Method to find multiple elements by their name
public ReadOnlyCollection<T>? FindElementsByName<T>(string name, int timeoutInMilliseconds = 3000)
// ind elements by name
public ReadOnlyCollection<T>? FindElementsByName<T>(string name, int timeoutMS = 3000)
where T : Element, new()
{
Assert.IsNotNull(WindowsDriver, "WindowsElement is null");
return FindElementHelper.FindElements<T, WindowsElement>(() => WindowsDriver.FindElementsByName(name), timeoutInMilliseconds, WindowsDriver);
return FindElementHelper.FindElements<T, WindowsElement>(() => WindowsDriver.FindElementsByName(name), timeoutMS, WindowsDriver);
}

// Method to take control of an existing application
// Attach to an existing exe by window name
public Session? Attach(PowerToysModuleWindow module)
{
string windowName = ModuleConfigData.Instance.GetModuleWindowData(module).WindowName;
Expand Down
Loading

1 comment on commit d934628

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@check-spelling-bot Report

🔴 Please review

See the 📜action log or 📝 job summary for details.

Unrecognized words (3)

Fancyzone
interited
MInstance

These words are not needed and should be removed ahk AMPROPERTY AMPROPSETID Breadcrumb CDEF comdef ddf devenum DEVMON DEVSOURCE DGR DIIRFLAG dshow DVH DVHD DVSD DVSL EData ERole fdw FILEINFOSIG Filtergraph Filterx HCERTSTORE IKs iljxck IYUV KSPROPERTY lcb ldx lld LONGLONG LTRB majortype makecab MEDIASUBTYPE mediatype mfplat mic mjpg Msimg msiquery ORAW outpin overlaywindow PAUDIO PINDIR Pnp ppmt previouscamera PROPBAG propvarutil reencode reencoded REFGUID REGFILTER REGFILTERPINS REGPINTYPES regsvr shmem sizeread stl strsafe strutil subquery SYNCMFT TMPVAR vcdl vdi vid VIDCAP VIDEOINFOHEADER vih webcam wistd WVC

To accept these unrecognized words as correct and remove the previously acknowledged and now absent words, you could run the following commands

... in a clone of the [email protected]:microsoft/PowerToys.git repository
on the zhaopengwang/UITestAutomation branch (ℹ️ how do I use this?):

curl -s -S -L 'https://raw.githubusercontent.com/check-spelling/check-spelling/v0.0.24/apply.pl' |
perl - 'https://github.com/microsoft/PowerToys/actions/runs/13328869971/attempts/1'
If the flagged items are 🤯 false positives

If items relate to a ...

  • binary file (or some other file you wouldn't want to check at all).

    Please add a file path to the excludes.txt file matching the containing file.

    File paths are Perl 5 Regular Expressions - you can test yours before committing to verify it will match your files.

    ^ refers to the file's path from the root of the repository, so ^README\.md$ would exclude README.md (on whichever branch you're using).

  • well-formed pattern.

    If you can write a pattern that would match it,
    try adding it to the patterns.txt file.

    Patterns are Perl 5 Regular Expressions - you can test yours before committing to verify it will match your lines.

    Note that patterns can't match multiline strings.

Please sign in to comment.