Skip to content

Commit

Permalink
Create uitest for keyboardmanager and api for element clicking by hel… (
Browse files Browse the repository at this point in the history
#37007)

Create uitest for keyboardmanager and api for element clicking by helpText

Co-authored-by: Xiaofeng Wang (from Dev Box) <[email protected]>
  • Loading branch information
urnotdfs and Xiaofeng Wang (from Dev Box) authored Jan 22, 2025
1 parent 342d24c commit e801ca2
Show file tree
Hide file tree
Showing 4 changed files with 165 additions and 11 deletions.
25 changes: 16 additions & 9 deletions PowerToys.sln
Original file line number Diff line number Diff line change
Expand Up @@ -628,17 +628,17 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AdvancedPaste.UnitTests", "
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AdvancedPaste.FuzzTests", "src\modules\AdvancedPaste\AdvancedPaste.FuzzTests\AdvancedPaste.FuzzTests.csproj", "{7F5B9557-5878-4438-A721-3E28296BA193}"
EndProject
<<<<<<< HEAD
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "ZoomIt", "ZoomIt", "{DD6E12FE-5509-4ABC-ACC2-3D6DC98A238C}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ZoomIt", "src\modules\ZoomIt\ZoomIt\ZoomIt.vcxproj", "{0A84F764-3A88-44CD-AA96-41BDBD48627B}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ZoomItModuleInterface", "src\modules\ZoomIt\ZoomItModuleInterface\ZoomItModuleInterface.vcxproj", "{E4585179-2AC1-4D5F-A3FF-CFC5392F694C}"
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}") = "UITestAPI", "src\UITestAPI\UITestAPI.csproj", "{6190BD46-AF95-49E6-8B7E-89B923CDE845}"
>>>>>>> 11da69271 (add UI test framework code)
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "KeyboardManagerUITests", "src\modules\keyboardmanager\KeyboardManagerUITests\KeyboardManagerUITests.csproj", "{A62BA56B-0A0B-4BBE-B570-F1CF80003274}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down Expand Up @@ -2802,7 +2802,6 @@ Global
{7F5B9557-5878-4438-A721-3E28296BA193}.Release|x64.Build.0 = Release|x64
{7F5B9557-5878-4438-A721-3E28296BA193}.Release|x86.ActiveCfg = Release|x64
{7F5B9557-5878-4438-A721-3E28296BA193}.Release|x86.Build.0 = Release|x64
<<<<<<< HEAD
{0A84F764-3A88-44CD-AA96-41BDBD48627B}.Debug|ARM64.ActiveCfg = Debug|ARM64
{0A84F764-3A88-44CD-AA96-41BDBD48627B}.Debug|ARM64.Build.0 = Debug|ARM64
{0A84F764-3A88-44CD-AA96-41BDBD48627B}.Debug|x64.ActiveCfg = Debug|x64
Expand Down Expand Up @@ -2839,7 +2838,6 @@ 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
=======
{6190BD46-AF95-49E6-8B7E-89B923CDE845}.Debug|ARM64.ActiveCfg = Debug|ARM64
{6190BD46-AF95-49E6-8B7E-89B923CDE845}.Debug|ARM64.Build.0 = Debug|ARM64
{6190BD46-AF95-49E6-8B7E-89B923CDE845}.Debug|x64.ActiveCfg = Debug|x64
Expand All @@ -2852,7 +2850,18 @@ Global
{6190BD46-AF95-49E6-8B7E-89B923CDE845}.Release|x64.Build.0 = Release|x64
{6190BD46-AF95-49E6-8B7E-89B923CDE845}.Release|x86.ActiveCfg = Release|x64
{6190BD46-AF95-49E6-8B7E-89B923CDE845}.Release|x86.Build.0 = Release|x64
>>>>>>> 11da69271 (add UI test framework code)
{A62BA56B-0A0B-4BBE-B570-F1CF80003274}.Debug|ARM64.ActiveCfg = Debug|ARM64
{A62BA56B-0A0B-4BBE-B570-F1CF80003274}.Debug|ARM64.Build.0 = Debug|ARM64
{A62BA56B-0A0B-4BBE-B570-F1CF80003274}.Debug|x64.ActiveCfg = Debug|x64
{A62BA56B-0A0B-4BBE-B570-F1CF80003274}.Debug|x64.Build.0 = Debug|x64
{A62BA56B-0A0B-4BBE-B570-F1CF80003274}.Debug|x86.ActiveCfg = Debug|x64
{A62BA56B-0A0B-4BBE-B570-F1CF80003274}.Debug|x86.Build.0 = Debug|x64
{A62BA56B-0A0B-4BBE-B570-F1CF80003274}.Release|ARM64.ActiveCfg = Release|ARM64
{A62BA56B-0A0B-4BBE-B570-F1CF80003274}.Release|ARM64.Build.0 = Release|ARM64
{A62BA56B-0A0B-4BBE-B570-F1CF80003274}.Release|x64.ActiveCfg = Release|x64
{A62BA56B-0A0B-4BBE-B570-F1CF80003274}.Release|x64.Build.0 = Release|x64
{A62BA56B-0A0B-4BBE-B570-F1CF80003274}.Release|x86.ActiveCfg = Release|x64
{A62BA56B-0A0B-4BBE-B570-F1CF80003274}.Release|x86.Build.0 = Release|x64
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -3084,14 +3093,12 @@ Global
{0DB0F63A-D2F8-4DA3-A650-2D0B8724218E} = {CA716AE6-FE5C-40AC-BB8F-2C87912687AC}
{D5E5F5EA-1B6C-4A73-88BE-304F36C9E4EE} = {9873BA05-4C41-4819-9283-CF45D795431B}
{7F5B9557-5878-4438-A721-3E28296BA193} = {9873BA05-4C41-4819-9283-CF45D795431B}
<<<<<<< HEAD
{DD6E12FE-5509-4ABC-ACC2-3D6DC98A238C} = {4574FDD0-F61D-4376-98BF-E5A1262C11EC}
{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}
=======
{6190BD46-AF95-49E6-8B7E-89B923CDE845} = {1AFB6476-670D-4E80-A464-657E01DFF482}
>>>>>>> 11da69271 (add UI test framework code)
{A62BA56B-0A0B-4BBE-B570-F1CF80003274} = {38BDB927-829B-4C65-9CD9-93FB05D66D65}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {C3A2F9D1-7930-4EF4-A6FC-7EE0A99821D0}
Expand Down
46 changes: 44 additions & 2 deletions src/UITestAPI/src/UITestAPI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// See the LICENSE file in the project root for more information.

using System;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.IO;
Expand Down Expand Up @@ -89,7 +90,14 @@ public void Close(TestContext testContext)

private WindowsElement? GetElement(string elementName)
{
var listItem = Session?.FindElementByName(elementName);
var item = Session?.FindElementByName(elementName);
Assert.IsNotNull(item, "ElementName " + elementName + " not found");
return item;
}

private ReadOnlyCollection<WindowsElement> GetElements(string elementName)
{
var listItem = Session?.FindElementsByName(elementName);
Assert.IsNotNull(listItem, "ElementName " + elementName + " not found");
return listItem;
}
Expand All @@ -107,11 +115,45 @@ public void Click_Element(string elementName)
var element = GetElement(elementName);
Actions actions = new Actions(Session);
actions.MoveToElement(element);
actions.MoveByOffset(30, 30);
actions.Click();
actions.Build().Perform();
}

public void Click_Elements(string elementName)
{
var elements = GetElements(elementName);
Actions actions = new Actions(Session);
foreach (var element in elements)
{
actions.MoveToElement(element);

actions.MoveByOffset(5, 5);
actions.Click();
actions.Build().Perform();
}
}

public void Click_Element(string elementName, string helpText)
{
var elements = GetElements(elementName);
Actions actions = new Actions(Session);
bool buttonClicked = false;
foreach (var element in elements)
{
if (element.GetAttribute("HelpText") == helpText)
{
actions.MoveToElement(element);
actions.Click();
actions.Build().Perform();
actions.MoveByOffset(5, 5);
buttonClicked = true;
break;
}
}

Assert.IsTrue(buttonClicked, $"No button with elementName '{elementName}' and HelpText '{helpText}' was found.");
}

public void RightClick_Element(string elementName)
{
var element = GetElement(elementName);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<Project Sdk="Microsoft.NET.Sdk">
<!-- Look at Directory.Build.props in root for common stuff as well -->
<Import Project="..\..\..\Common.Dotnet.CsWinRT.props" />

<PropertyGroup>
<ProjectGuid>{6F8C7C5A-130A-48C2-A245-3132A4121E24}</ProjectGuid>
<RootNamespace>Microsoft.KeyboardManager.UITests</RootNamespace>
<IsPackable>false</IsPackable>
<Nullable>enable</Nullable>
<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" />
<PackageReference Include="System.IO.Abstractions" />
</ItemGroup>

<ItemGroup>
<Folder Include="Properties\" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\UITestAPI\UITestAPI.csproj" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
// 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.Diagnostics;
using Microsoft.UITests.API;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace UITests_KeyboardManager
{
[TestClass]
public class RunKeyboardManagerUITests
{
private const string PowerToysSettingsPath = @"\..\..\..\WinUI3Apps\PowerToys.Settings.exe";
private static UITestAPI? _uITestAPI;

private static TestContext? _context;

[AssemblyInitialize]
public static void SetupAll(TestContext context)
{
Debug.WriteLine("AssemblyInitialize executed");
}

[AssemblyCleanup]
public static void CleanupAll()
{
Debug.WriteLine("AssemblyCleanup executed");
}

[ClassInitialize]
public static void ClassInitialize(TestContext testContext)
{
_uITestAPI = new UITestAPI();
_uITestAPI.Init(PowerToysSettingsPath);
Debug.WriteLine("ClassInitialize executed");
}

[ClassCleanup]
public static void ClassCleanup()
{
if (_uITestAPI != null && _context != null)
{
_uITestAPI.Close(_context);
}

_context = null;
Debug.WriteLine("ClassCleanup executed");
}

[TestInitialize]
public void TestInitialize()
{
Debug.WriteLine("TestInitialize executed");
}

[TestCleanup]
public void TestCleanup()
{
Debug.WriteLine("TestCleanup executed");
}

[TestMethod]
public void EnableKeyboardManager() // verify the session is initialized
{
Debug.WriteLine("Test method executed");
Assert.IsNotNull(_uITestAPI);
_uITestAPI.Click_Element("Enable module", "Keyboard Manager");
}
}
}

1 comment on commit e801ca2

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

ITest

These words are not needed and should be removed accctrl aclapi AMPROPERTY AMPROPSETID appdata Appium appmodel atlbase atlcom atlfile atlstr bootstrapper caniuse CDEF ceq cguid Cmds cne codicon comdef commandline commctrl commdlg comutil consts contentdialog cppwinrt CRSEL crx dcommon dcomp DCs ddf desktopwindowxamlsource devenum DEVMON devpkey DEVSOURCE DIIRFLAG dshow DVH DVHD DVSD DVSL dxgidebug dxgiformat EData emmintrin Emoji endpointvolume ERole evntrace exdisp fdw FILEINFOSIG Filtergraph Filterx Functiondiscoverykeys guiddef HCERTSTORE hinstance hstring IKs iljxck Intelli ipreviewhandlervisualssetfont IYUV junja Knownfolders KSPROPERTY lcb ldx lld lmcons LONGLONG lpt LTRB majortype makecab MEDIASUBTYPE mediatype mfapi mfidl mfobjects mfplat mftransform mic Minimatch mjpg mmdeviceapi mmsystem msedge Msimg msiquery newdev nodoc notlike ntfs Objbase objidl ORAW outpin outputtype overlaywindow pathcch PAUDIO PINDIR Pnp ppmt Preinstalled previouscamera processthreadsapi PROPBAG propkey propvarutil redistributable reencode reencoded REFGUID REGFILTER REGFILTERPINS REGPINTYPES regsvr Renamer reparse restrictederrorinfo roadmap ruleset runtimes shellapi shellscalingapi shldisp shlobj shmem sizeread stl strsafe strutil subquery SWC SYNCMFT tailwindcss tapp thumbcache tlhelp TMPVAR Toolset touchpad Tsd uninstantiated uniquifier Unknwn unregistering urlmon USERDATA vcdl vdi verrsrc vid VIDCAP VIDEOINFOHEADER vih wcautil webcam wincodec Wincodecsdk windef windowsapp windowsx winerror winevt winexe winforms winsdkver winternl wistd wsl wtsapi 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/UITestAPI 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/12906513989/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.