Skip to content

Commit

Permalink
Add UITestAutomation framework
Browse files Browse the repository at this point in the history
  • Loading branch information
Zhaopeng Wang (from Dev Box) committed Feb 14, 2025
1 parent 5008d77 commit 8d334e4
Show file tree
Hide file tree
Showing 12 changed files with 691 additions and 56 deletions.
15 changes: 15 additions & 0 deletions PowerToys.sln
Original file line number Diff line number Diff line change
Expand Up @@ -636,6 +636,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ZoomItModuleInterface", "sr
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ZoomItSettingsInterop", "src\modules\ZoomIt\ZoomItSettingsInterop\ZoomItSettingsInterop.vcxproj", "{CA7D8106-30B9-4AEC-9D05-B69B31B8C461}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UITestAutomation", "src\common\UITestAutomation\UITestAutomation.csproj", "{A558C25D-2007-498E-8B6F-43405AFAE9E2}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|ARM64 = Debug|ARM64
Expand Down Expand Up @@ -2834,6 +2836,18 @@ Global
{CA7D8106-30B9-4AEC-9D05-B69B31B8C461}.Release|x64.Build.0 = Release|x64
{CA7D8106-30B9-4AEC-9D05-B69B31B8C461}.Release|x86.ActiveCfg = Release|x64
{CA7D8106-30B9-4AEC-9D05-B69B31B8C461}.Release|x86.Build.0 = Release|x64
{A558C25D-2007-498E-8B6F-43405AFAE9E2}.Debug|ARM64.ActiveCfg = Debug|ARM64
{A558C25D-2007-498E-8B6F-43405AFAE9E2}.Debug|ARM64.Build.0 = Debug|ARM64
{A558C25D-2007-498E-8B6F-43405AFAE9E2}.Debug|x64.ActiveCfg = Debug|x64
{A558C25D-2007-498E-8B6F-43405AFAE9E2}.Debug|x64.Build.0 = Debug|x64
{A558C25D-2007-498E-8B6F-43405AFAE9E2}.Debug|x86.ActiveCfg = Debug|x64
{A558C25D-2007-498E-8B6F-43405AFAE9E2}.Debug|x86.Build.0 = Debug|x64
{A558C25D-2007-498E-8B6F-43405AFAE9E2}.Release|ARM64.ActiveCfg = Release|ARM64
{A558C25D-2007-498E-8B6F-43405AFAE9E2}.Release|ARM64.Build.0 = Release|ARM64
{A558C25D-2007-498E-8B6F-43405AFAE9E2}.Release|x64.ActiveCfg = Release|x64
{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
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -3069,6 +3083,7 @@ Global
{0A84F764-3A88-44CD-AA96-41BDBD48627B} = {DD6E12FE-5509-4ABC-ACC2-3D6DC98A238C}
{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}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {C3A2F9D1-7930-4EF4-A6FC-7EE0A99821D0}
Expand Down
27 changes: 27 additions & 0 deletions src/common/UITestAutomation/Element/Button.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// 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 Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenQA.Selenium;
using OpenQA.Selenium.Appium.Windows;
using OpenQA.Selenium.Interactions;
using OpenQA.Selenium.Remote;
using OpenQA.Selenium.Support.Events;

namespace Microsoft.PowerToys.UITest
{
public class Button : Element
{
public Button()
: base()
{
}

public string GetButtonType()
{
Assert.IsNotNull(WindowsElement, "WindowsElement should not be null");
return WindowsElement.GetAttribute("ControlType");
}
}
}
54 changes: 54 additions & 0 deletions src/common/UITestAutomation/Element/By.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// 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 OpenQA.Selenium;

namespace Microsoft.PowerToys.UITest
{
#pragma warning disable SA1649 // File name should match first type name
public class By
{
private readonly OpenQA.Selenium.By by;

private By(OpenQA.Selenium.By by)
{
this.by = by;
}

public static By Name(string name)
{
return new By(OpenQA.Selenium.By.Name(name));
}

public static By Id(string id)
{
return new By(OpenQA.Selenium.By.Id(id));
}

public static By XPath(string xpath)
{
return new By(OpenQA.Selenium.By.XPath(xpath));
}

public static By CssSelector(string cssSelector)
{
return new By(OpenQA.Selenium.By.CssSelector(cssSelector));
}

public static By LinkText(string linkText)
{
return new By(OpenQA.Selenium.By.LinkText(linkText));
}

public static By TagName(string tagName)
{
return new By(OpenQA.Selenium.By.TagName(tagName));
}

public OpenQA.Selenium.By ToSeleniumBy()
{
return by;
}
}
}
203 changes: 203 additions & 0 deletions src/common/UITestAutomation/Element/Element.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,203 @@
// 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.Collections.ObjectModel;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenQA.Selenium;
using OpenQA.Selenium.Appium.Windows;
using OpenQA.Selenium.Interactions;
using OpenQA.Selenium.Remote;
using OpenQA.Selenium.Support.Events;
using static Microsoft.PowerToys.UITest.UITestBase;

namespace Microsoft.PowerToys.UITest
{
public class Element
{
public WindowsElement? WindowsElement { get; set; }

private WindowsDriver<WindowsElement>? driver;

public Element()
{
WindowsElement = null;
}

public void SetWindowsElement(WindowsElement windowsElement)
{
WindowsElement = windowsElement;
}

public void SetSession(WindowsDriver<WindowsElement> driver)
{
this.driver = driver;
}

public string GetName()
{
if (WindowsElement == null)
{
Assert.IsNotNull(null);
return " ";
}

return WindowsElement.GetAttribute("Name");
}

public string GetText()
{
if (WindowsElement == null)
{
Assert.IsNotNull(null);
return " ";
}

return WindowsElement.GetAttribute("Value");
}

public string GetAutomationId()
{
if (WindowsElement == null)
{
Assert.IsNotNull(null);
return " ";
}

return WindowsElement.GetAttribute("AutomationId");
}

public string GetClassName()
{
if (WindowsElement == null)
{
Assert.IsNotNull(null);
return " ";
}

return WindowsElement.GetAttribute("ClassName");
}

public string GetHelpText()
{
if (WindowsElement == null)
{
Assert.IsNotNull(null);
return " ";
}

return WindowsElement.GetAttribute("HelpText");
}

public bool IsEnable()
{
if (WindowsElement == null)
{
Assert.IsNotNull(null);
}

return WindowsElement?.GetAttribute("IsEnabled") == "True" ? true : false;
}

public bool IsSelected()
{
if (WindowsElement == null)
{
Assert.IsNotNull(null);
}

return WindowsElement?.GetAttribute("IsSelected") == "True" ? true : false;
}

public void Click()
{
var element = WindowsElement;
Actions actions = new Actions(driver);
actions.MoveToElement(element);
actions.Click();
actions.Build().Perform();
}

public void RightClick()
{
var element = WindowsElement;
Actions actions = new Actions(driver);
actions.MoveToElement(element);
actions.MoveByOffset(5, 5);
actions.ContextClick();
actions.Build().Perform();
}

public void ClickCheckAttribute(string attributeKey, string attributeValue)
{
var elements = WindowsElement;
Actions actions = new Actions(driver);
if (elements?.GetAttribute(attributeKey) == attributeValue)
{
actions.MoveToElement(elements);
actions.Click();
actions.Build().Perform();
actions.MoveByOffset(5, 5);
}
}

public bool CheckAttribute(string attributeKey, string attributeValue)
{
var elements = WindowsElement;
return elements?.GetAttribute(attributeKey) == attributeValue;
}

public T FindElementByName<T>(string name)
where T : Element, new()
{
var item = WindowsElement?.FindElementByName(name) as WindowsElement;
Assert.IsNotNull(item, "Can`t find this element");
T element = new T();
element.SetWindowsElement(item);
return element;
}

public T? FindElementByAccessibilityId<T>(string name)
where T : Element, new()
{
var item = WindowsElement?.FindElementByAccessibilityId(name) as WindowsElement;
Assert.IsNotNull(item, "Can`t find this element");
T element = new T();
element.SetWindowsElement(item);
return element;
}

public ReadOnlyCollection<T>? FindElementsByName<T>(string name)
where T : Element, new()
{
var items = WindowsElement?.FindElementsByName(name);
Assert.IsNotNull(items, "Can`t find this element");
List<T> res = new List<T>();
foreach (var item in items)
{
T element = new T();
var itemTemp = item as WindowsElement;
if (itemTemp != null)
{
element.SetWindowsElement(itemTemp);
}

res.Add(element);
}

var resReadOnlyCollection = new ReadOnlyCollection<T>(res);
return resReadOnlyCollection;
}

public Screenshot? GetScreenShot()
{
if (WindowsElement == null)
{
Assert.IsNotNull(null);
return null;
}

return WindowsElement?.GetScreenshot();
}
}
}
51 changes: 51 additions & 0 deletions src/common/UITestAutomation/Element/Window.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// 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 Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenQA.Selenium;
using OpenQA.Selenium.Appium.Windows;
using OpenQA.Selenium.Interactions;
using OpenQA.Selenium.Remote;
using OpenQA.Selenium.Support.Events;

namespace Microsoft.PowerToys.UITest
{
public class Window : Element
{
public Window()
: base()
{
}

public bool IsVisible()
{
Assert.IsNotNull(WindowsElement, "WindowsElement should not be null");
return WindowsElement.Displayed;
}

public Window Maximize()
{
Assert.IsNotNull(WindowsElement, "WindowsElement should not be null");
Assert.IsTrue(IsVisible(), "Window is not visible");
FindElementByName<Button>("Maximize").Click();
return this;
}

public Window Restore()
{
Assert.IsNotNull(WindowsElement, "WindowsElement should not be null");
Assert.IsTrue(IsVisible(), "Window is not visible");
FindElementByName<Button>("Restore").Click();
return this;
}

public Window Minimize()
{
Assert.IsNotNull(WindowsElement, "WindowsElement should not be null");
Assert.IsTrue(IsVisible(), "Window is not visible");
FindElementByName<Button>("Minimize").Click();
return this;
}
}
}
Loading

1 comment on commit 8d334e4

@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 (2)

Fancyzone
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/13325243372/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.