-
Notifications
You must be signed in to change notification settings - Fork 6.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Zhaopeng Wang (from Dev Box)
committed
Feb 14, 2025
1 parent
5008d77
commit 8d334e4
Showing
12 changed files
with
691 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |
Oops, something went wrong.
8d334e4
There was a problem hiding this comment.
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 WVCTo 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?):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.