Skip to content

Commit 9fccd86

Browse files
urnotdfsXiaofeng Wang (from Dev Box)
andauthored
Add Module Enable/Disable API and update window operation function in UIManager (#37047)
* 1. Enable/Disable API 2. Fix UIManager 3. Fix FancyZone UI test * Fix spelling error --------- Co-authored-by: Xiaofeng Wang (from Dev Box) <[email protected]>
1 parent 300aa9f commit 9fccd86

File tree

4 files changed

+86
-13
lines changed

4 files changed

+86
-13
lines changed

src/UITestAPI/src/UIManager.cs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,16 @@ public void StartApp(string appName, string windowName, string appPath)
7676
winDriver.Session = session;
7777
winDriver.AppName = appName;
7878
winDriver.WindowName = windowName;
79-
mWindowList.Push(winDriver);
79+
if (CurrentDriver.Session != null)
80+
{
81+
mWindowList.Push(CurrentDriver);
82+
}
83+
8084
CurrentDriver = winDriver;
8185
}
8286

8387
// Take control of an application that already exists
84-
public void LuanchApp(string appName, string windowName)
88+
public void LaunchApp(string appName, string windowName)
8589
{
8690
if (Root != null)
8791
{
@@ -103,7 +107,11 @@ public void LuanchApp(string appName, string windowName)
103107
winDriver.Session = appSession;
104108
winDriver.AppName = appName;
105109
winDriver.WindowName = windowName;
106-
mWindowList.Push(winDriver);
110+
if (CurrentDriver.Session != null)
111+
{
112+
mWindowList.Push(CurrentDriver);
113+
}
114+
107115
CurrentDriver = winDriver;
108116
}
109117
else
@@ -158,6 +166,7 @@ public void CloseApp(string appName)
158166
}
159167

160168
CurrentDriver = mWindowList.Pop();
169+
return;
161170
}
162171

163172
while (mWindowList.Count > 0)

src/UITestAPI/src/UITestAPI.cs

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,9 @@ public void StartApp(string appName, string windowName, string appPath)
7676
}
7777

7878
// Take control of an application that already exists
79-
public void LuanchApp(string appName, string windowName)
79+
public void LaunchApp(string appName, string windowName)
8080
{
81-
UIManager.LuanchApp(appName, windowName);
81+
UIManager.LaunchApp(appName, windowName);
8282
}
8383

8484
// Use the name to switch the current driver
@@ -182,6 +182,58 @@ public void Click_Element(string elementName, string helpText, string? appName =
182182
Assert.IsTrue(buttonClicked, $"No button with elementName '{elementName}' and HelpText '{helpText}' was found.");
183183
}
184184

185+
public void Enable_Module_from_Dashboard(string moduleName, string? appName = null)
186+
{
187+
WindowsDriver<WindowsElement>? session = GetSession(appName);
188+
var elements = GetElements("Enable module");
189+
Actions actions = new Actions(session);
190+
bool buttonFound = false;
191+
foreach (var element in elements)
192+
{
193+
if (element.GetAttribute("HelpText") == moduleName)
194+
{
195+
if (element.GetAttribute("Toggle.ToggleState") == "0")
196+
{
197+
actions.MoveToElement(element);
198+
actions.Click();
199+
actions.Build().Perform();
200+
actions.MoveByOffset(5, 5);
201+
}
202+
203+
buttonFound = true;
204+
break;
205+
}
206+
}
207+
208+
Assert.IsTrue(buttonFound, $"No button with elementName '{moduleName}' and HelpText '{moduleName}' was found.");
209+
}
210+
211+
public void Disable_Module_from_Dashboard(string moduleName, string? appName = null)
212+
{
213+
WindowsDriver<WindowsElement>? session = GetSession(appName);
214+
var elements = GetElements("Enable module");
215+
Actions actions = new Actions(session);
216+
bool buttonFound = false;
217+
foreach (var element in elements)
218+
{
219+
if (element.GetAttribute("HelpText") == moduleName)
220+
{
221+
if (element.GetAttribute("Toggle.ToggleState") == "1")
222+
{
223+
actions.MoveToElement(element);
224+
actions.Click();
225+
actions.Build().Perform();
226+
actions.MoveByOffset(5, 5);
227+
}
228+
229+
buttonFound = true;
230+
break;
231+
}
232+
}
233+
234+
Assert.IsTrue(buttonFound, $"No button with elementName '{moduleName}' and HelpText '{moduleName}' was found.");
235+
}
236+
185237
public void RightClick_Element(string elementName, string? appName = null)
186238
{
187239
WindowsDriver<WindowsElement>? session = GetSession(appName);

src/modules/fancyzones/UITests-FancyZones/RunFancyZonesTest.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using System.Collections.Generic;
77
using System.Runtime.InteropServices;
88
using System.Text;
9+
using System.Threading;
910
using Microsoft.FancyZones.UnitTests.Utils;
1011
using Microsoft.UITests.API;
1112
using Microsoft.VisualStudio.TestTools.UnitTesting;
@@ -86,8 +87,10 @@ public void RunFancyZones()
8687
}
8788

8889
Assert.IsNotNull(mUITestAPI);
90+
mUITestAPI.Click_Element("Launch layout editor");
8991

90-
mUITestAPI.LuanchApp("PowerToys.FancyZonesEditor", "FancyZones Editor");
92+
Thread.Sleep(5000);
93+
mUITestAPI.LaunchApp("PowerToys.FancyZonesEditor", "FancyZones Layout");
9194
mUITestAPI?.Click_CreateNewLayout();
9295
}
9396
}

src/modules/keyboardmanager/KeyboardManagerUITests/RunKeyboardManagerUITests.cs

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System;
66
using System.Collections.Generic;
77
using System.Diagnostics;
8+
using System.Threading;
89
using Microsoft.UITests.API;
910
using Microsoft.VisualStudio.TestTools.UnitTesting;
1011

@@ -14,7 +15,7 @@ namespace UITests_KeyboardManager
1415
public class RunKeyboardManagerUITests
1516
{
1617
private const string PowerToysSettingsPath = @"\..\..\..\WinUI3Apps\PowerToys.Settings.exe";
17-
private static UITestAPI? _uITestAPI;
18+
private static UITestAPI? mUITestAPI;
1819

1920
private static TestContext? _context;
2021

@@ -33,17 +34,17 @@ public static void CleanupAll()
3334
[ClassInitialize]
3435
public static void ClassInitialize(TestContext testContext)
3536
{
36-
_uITestAPI = new UITestAPI();
37-
_uITestAPI.Init("PowerToys.Settings", PowerToysSettingsPath, "PowerToys.Settings");
37+
mUITestAPI = new UITestAPI();
38+
mUITestAPI.Init("PowerToys.Settings", PowerToysSettingsPath, "PowerToys.Settings");
3839
Debug.WriteLine("ClassInitialize executed");
3940
}
4041

4142
[ClassCleanup]
4243
public static void ClassCleanup()
4344
{
44-
if (_uITestAPI != null && _context != null)
45+
if (mUITestAPI != null && _context != null)
4546
{
46-
_uITestAPI.Close(_context);
47+
mUITestAPI.Close(_context);
4748
}
4849

4950
_context = null;
@@ -66,8 +67,16 @@ public void TestCleanup()
6667
public void EnableKeyboardManager() // verify the session is initialized
6768
{
6869
Debug.WriteLine("Test method executed");
69-
Assert.IsNotNull(_uITestAPI);
70-
_uITestAPI.Click_Element("Enable module", "Keyboard Manager");
70+
Assert.IsNotNull(mUITestAPI);
71+
72+
mUITestAPI.Enable_Module_from_Dashboard("Keyboard Manager");
73+
mUITestAPI.Click_Element("Remap a key");
74+
Thread.Sleep(5000);
75+
mUITestAPI.LaunchApp("PowerToys.KeyboardManagerEditor", "Remap keys");
76+
mUITestAPI.Click_Element("Add key remapping");
77+
mUITestAPI.Click_Element("Cancel");
78+
mUITestAPI.CloseApp("PowerToys.KeyboardManagerEditor");
79+
mUITestAPI.Disable_Module_from_Dashboard("Keyboard Manager");
7180
}
7281
}
7382
}

0 commit comments

Comments
 (0)