-
Notifications
You must be signed in to change notification settings - Fork 6.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
UITestAutomation Framework #37461
Merged
+889
−0
Merged
UITestAutomation Framework #37461
Changes from all commits
Commits
Show all changes
37 commits
Select commit
Hold shift + click to select a range
8d334e4
Add UITestAutomation framework
3f5e7d5
add code comments
785086a
Optimized code format
f6b1765
Optimized code format
8e542b0
Update commons and add keyboard manager ui test project
a5bb9a1
Optimized code format
d934628
fix mergeing
89d5ffb
test scope and fix fancyzone exe path
4f15b63
Add readme
931cf95
Optimize helper functions and UI test method
430702e
Fix spelling errors and restore module UI tests
3a1e57f
Restore Indent
a0cecb8
Update NOTICE.md
aba029d
Update comments to Session and Elements
0785c67
Update comments for Button and Window
d535199
delete unnecessary code
708b975
Merge branch 'zhaopengwang/UITestAutomation' of https://github.com/mi…
3ae2397
change FindElementByName to FindElmenet
3b47f5e
Update comments for ModuleConfigData
7ed5765
Merge branch 'zhaopengwang/UITestAutomation' of https://github.com/mi…
81a4a7a
Update readme and comments
6dfe364
Remove extra comments
41ffa68
change public property
5841086
Merge branch 'zhaopengwang/UITestAutomation' of https://github.com/mi…
5753adc
Optimize code readability
bd394f0
add default Attach Function
a50b085
change attach function name
36bbb62
Update comments to XML format
ae1e313
Hide by internal functions
6c08723
Update readme
89b8046
Refine the framework
680a314
Fix process start position and update readme
e435490
Merge branch 'main' into zhaopengwang/UITestAutomation
urnotdfs e008f17
Merge branch 'main' into zhaopengwang/UITestAutomation
urnotdfs 3653568
Remove Enum PowerToysModuleWindow
9da02e4
Update attach comments
4d58b05
Update ModuleConfigData comments
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,91 @@ | ||
# UI tests framework | ||
|
||
A specialized UI test framework for PowerToys that makes it easy to write UI tests for PowerToys modules or settings. Let's start writing UI tests! | ||
|
||
## Before running tests | ||
|
||
- Install Windows Application Driver v1.2.1 from https://github.com/microsoft/WinAppDriver/releases/tag/v1.2.1 to the default directory (`C:\Program Files (x86)\Windows Application Driver`) | ||
|
||
- Enable Developer Mode in Windows settings | ||
|
||
## Running tests | ||
|
||
- Exit PowerToys if it's running. | ||
|
||
- Open `PowerToys.sln` in Visual Studio and build the solution. | ||
|
||
- Run tests in the Test Explorer (`Test > Test Explorer` or `Ctrl+E, T`). | ||
|
||
|
||
## How to add the first UI tests for your modules | ||
|
||
- Create a new project and add the following references to the project file. Change the OutputPath to your own module's path. | ||
``` | ||
<PropertyGroup> | ||
<OutputType>Library</OutputType> | ||
<!-- This is a UI test, so don't run as part of MSBuild --> | ||
<RunVSTest>false</RunVSTest> | ||
</PropertyGroup> | ||
<PropertyGroup> | ||
<OutputPath>..\..\..\..\$(Platform)\$(Configuration)\tests\KeyboardManagerUITests\</OutputPath> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<PackageReference Include="MSTest" /> | ||
<ProjectReference Include="..\..\..\common\UITestAutomation\UITestAutomation.csproj" /> | ||
<Folder Include="Properties\" /> | ||
</ItemGroup> | ||
``` | ||
- Inherit your test class from UITestBase. | ||
>Set Scope: The default scope starts from the PowerToys settings UI. If you want to start from your own module, set the constructor as shown below: | ||
>Specify Scope: | ||
``` | ||
[TestClass] | ||
public class RunFancyZonesTest : UITestBase | ||
{ | ||
public RunFancyZonesTest() | ||
: base(PowerToysModule.FancyZone) | ||
{ | ||
} | ||
} | ||
``` | ||
|
||
- Then you can start using session to perform the UI operations. | ||
|
||
**Example** | ||
``` | ||
using Microsoft.PowerToys.UITest; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
namespace UITests_KeyboardManager | ||
{ | ||
[TestClass] | ||
public class RunKeyboardManagerUITests : UITestBase | ||
{ | ||
[TestMethod] | ||
public void OpenKeyboardManagerEditor() | ||
{ | ||
// Open KeyboardManagerEditor | ||
this.Session.Find<Button>(By.Name("Remap a key")).Click(); | ||
this.Session.Attach("Remap keys"); | ||
// Maximize window | ||
var window = Session.Find<Window>(By.Name("Remap keys")).Maximize(); | ||
// Add Key Remapping | ||
this.Session.Find<Button>(By.Name("Add key remapping")).Click(); | ||
window.Close(); | ||
// Back to Settings | ||
this.Session.Attach(PowerToysModule.PowerToysSettings); | ||
} | ||
} | ||
} | ||
``` | ||
|
||
## Extra tools and information | ||
|
||
**Accessibility Tools**: | ||
While working on tests, you may need a tool that helps you to view the element's accessibility data, e.g. for finding the button to click. For this purpose, you could use [AccessibilityInsights](https://accessibilityinsights.io/docs/windows/overview) |
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,20 @@ | ||
// 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 | ||
{ | ||
/// <summary> | ||
/// Represents a button in the UI test environment. | ||
/// </summary> | ||
public class Button : Element | ||
{ | ||
} | ||
} |
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,69 @@ | ||
// 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 static OpenQA.Selenium.By; | ||
|
||
namespace Microsoft.PowerToys.UITest | ||
{ | ||
/// <summary> | ||
/// This class represents a By selector. | ||
/// </summary> | ||
public class By | ||
{ | ||
private readonly OpenQA.Selenium.By by; | ||
|
||
private By(OpenQA.Selenium.By by) | ||
{ | ||
this.by = by; | ||
} | ||
|
||
/// <summary> | ||
/// Creates a By object using the name attribute. | ||
/// </summary> | ||
/// <param name="name">The name attribute to search for.</param> | ||
/// <returns>A By object.</returns> | ||
public static By Name(string name) => new By(OpenQA.Selenium.By.Name(name)); | ||
|
||
/// <summary> | ||
/// Creates a By object using the ID attribute. | ||
/// </summary> | ||
/// <param name="id">The ID attribute to search for.</param> | ||
/// <returns>A By object.</returns> | ||
public static By Id(string id) => new By(OpenQA.Selenium.By.Id(id)); | ||
|
||
/// <summary> | ||
/// Creates a By object using the XPath expression. | ||
/// </summary> | ||
/// <param name="xpath">The XPath expression to search for.</param> | ||
/// <returns>A By object.</returns> | ||
public static By XPath(string xpath) => new By(OpenQA.Selenium.By.XPath(xpath)); | ||
|
||
/// <summary> | ||
/// Creates a By object using the CSS selector. | ||
/// </summary> | ||
/// <param name="cssSelector">The CSS selector to search for.</param> | ||
/// <returns>A By object.</returns> | ||
public static By CssSelector(string cssSelector) => new By(OpenQA.Selenium.By.CssSelector(cssSelector)); | ||
|
||
/// <summary> | ||
/// Creates a By object using the link text. | ||
/// </summary> | ||
/// <param name="linkText">The link text to search for.</param> | ||
/// <returns>A By object.</returns> | ||
public static By LinkText(string linkText) => new By(OpenQA.Selenium.By.LinkText(linkText)); | ||
|
||
/// <summary> | ||
/// Creates a By object using the tag name. | ||
/// </summary> | ||
/// <param name="tagName">The tag name to search for.</param> | ||
/// <returns>A By object.</returns> | ||
public static By TagName(string tagName) => new By(OpenQA.Selenium.By.TagName(tagName)); | ||
|
||
/// <summary> | ||
/// Converts the By object to an OpenQA.Selenium.By object. | ||
/// </summary> | ||
/// <returns>An OpenQA.Selenium.By object.</returns> | ||
internal OpenQA.Selenium.By ToSeleniumBy() => by; | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
can this change to private or internal?
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.
No, Users will use the By type, which cannot be changed to private or internal. There is no way to authorize a file that does not exist.