Skip to content

Commit d9a4e44

Browse files
authored
[Testing] Implement PressEnter Appium action on Windows (#27602)
* Implement PressEnter appium action on Windows * Re-enable test on Windows
1 parent acd837d commit d9a4e44

File tree

3 files changed

+41
-4
lines changed

3 files changed

+41
-4
lines changed

src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Bugzilla/Bugzilla29453.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
#if TEST_FAILS_ON_WINDOWS //PressEnter Method not supported on Windows
2-
using NUnit.Framework;
1+
using NUnit.Framework;
32
using UITest.Appium;
43
using UITest.Core;
54

@@ -27,5 +26,4 @@ public void Bugzilla29453Test()
2726
App.WaitForElement("Page1");
2827
}
2928
}
30-
}
31-
#endif
29+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
using OpenQA.Selenium;
2+
using OpenQA.Selenium.Appium.Windows;
3+
using UITest.Core;
4+
5+
namespace UITest.Appium
6+
{
7+
public class AppiumWindowsVirtualKeyboardActions : AppiumVirtualKeyboardActions
8+
{
9+
readonly AppiumApp _appiumApp;
10+
11+
public AppiumWindowsVirtualKeyboardActions(AppiumApp app)
12+
: base(app)
13+
{
14+
_appiumApp = app;
15+
}
16+
17+
protected override CommandResponse PressEnter(IDictionary<string, object> parameters)
18+
{
19+
try
20+
{
21+
// Virtual-Key Codes: https://learn.microsoft.com/en-us/windows/win32/inputdev/virtual-key-codes
22+
_appiumApp.Driver.ExecuteScript("windows: keys", new Dictionary<string, object>
23+
{
24+
["actions"] = new[]
25+
{
26+
new Dictionary<string, object> { ["virtualKeyCode"] = 0x0D, ["down"]=false }, // Enter
27+
}
28+
});
29+
}
30+
catch (InvalidElementStateException)
31+
{
32+
return CommandResponse.FailedEmptyResponse;
33+
}
34+
35+
return CommandResponse.SuccessEmptyResponse;
36+
}
37+
}
38+
}

src/TestUtils/src/UITest.Appium/AppiumWindowsApp.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ public AppiumWindowsApp(Uri remoteAddress, IConfig config)
1212
{
1313
_commandExecutor.AddCommandGroup(new AppiumWindowsStepperActions(this));
1414
_commandExecutor.AddCommandGroup(new AppiumWindowsThemeChangeAction());
15+
_commandExecutor.AddCommandGroup(new AppiumWindowsVirtualKeyboardActions(this));
1516
}
1617

1718
public override ApplicationState AppState

0 commit comments

Comments
 (0)