Skip to content

Commit 8a54162

Browse files
authored
[UI Testing] Implement PressEnter method (#22112)
* Implement PressEnter method on appium * IsKeyboardShown not implemented on Windows * Updated test
1 parent e33d176 commit 8a54162

File tree

6 files changed

+50
-4
lines changed

6 files changed

+50
-4
lines changed

src/Controls/tests/UITests/Tests/Issues/Issue16386.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using NUnit.Framework;
2-
using OpenQA.Selenium;
32
using UITest.Appium;
43
using UITest.Core;
54

@@ -20,13 +19,12 @@ public void HittingEnterKeySendsDone()
2019
this.IgnoreIfPlatforms(new[]
2120
{
2221
TestDevice.Mac,
23-
TestDevice.iOS,
24-
TestDevice.Windows,
22+
TestDevice.Windows
2523
});
2624

2725
App.WaitForElement("HardwareEnterKeyEntry");
2826
App.Tap("HardwareEnterKeyEntry");
29-
App.SendKeys(66);
27+
App.PressEnter();
3028
App.WaitForElement("Success");
3129
}
3230
}

src/TestUtils/src/UITest.Appium/Actions/AppiumAndroidVirtualKeyboardActions.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,19 @@ protected override CommandResponse DismissKeyboard(IDictionary<string, object> p
1919
return CommandResponse.SuccessEmptyResponse;
2020
}
2121

22+
protected override CommandResponse PressEnter(IDictionary<string, object> parameters)
23+
{
24+
if (_app.Driver is AndroidDriver android)
25+
{
26+
// 66 - KEYCODE_ENTER
27+
// More information: https://developer.android.com/reference/android/view/KeyEvent.html
28+
android.PressKeyCode(66);
29+
return CommandResponse.SuccessEmptyResponse;
30+
}
31+
32+
return CommandResponse.FailedEmptyResponse;
33+
}
34+
2235
protected override CommandResponse PressVolumeDown(IDictionary<string, object> parameters)
2336
{
2437
if (_app.Driver is AndroidDriver android)

src/TestUtils/src/UITest.Appium/Actions/AppiumIOSVirtualKeyboardActions.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,23 @@ protected override CommandResponse DismissKeyboard(IDictionary<string, object> p
2727
return CommandResponse.SuccessEmptyResponse;
2828
}
2929

30+
protected override CommandResponse PressEnter(IDictionary<string, object> parameters)
31+
{
32+
try
33+
{
34+
if (_app.Driver.IsKeyboardShown())
35+
{
36+
_app.Driver.SwitchTo().ActiveElement().SendKeys(Keys.Return);
37+
}
38+
}
39+
catch (InvalidElementStateException)
40+
{
41+
return CommandResponse.FailedEmptyResponse;
42+
}
43+
44+
return CommandResponse.SuccessEmptyResponse;
45+
}
46+
3047
protected override CommandResponse PressVolumeDown(IDictionary<string, object> parameters)
3148
{
3249
try

src/TestUtils/src/UITest.Appium/Actions/AppiumVirtualKeyboardActions.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ public class AppiumVirtualKeyboardActions : ICommandExecutionGroup
66
{
77
const string IsKeyboardShownCommand = "isKeyboardShown";
88
const string HideKeyboardCommand = "dismissKeyboard";
9+
const string PressEnterCommand = "pressEnter";
910
const string PressVolumeDownCommand = "pressVolumeDown";
1011
const string PressVolumeUpCommand = "pressVolumeUp";
1112

@@ -14,6 +15,7 @@ public class AppiumVirtualKeyboardActions : ICommandExecutionGroup
1415
{
1516
IsKeyboardShownCommand,
1617
HideKeyboardCommand,
18+
PressEnterCommand,
1719
PressVolumeDownCommand,
1820
PressVolumeUpCommand,
1921
};
@@ -34,6 +36,7 @@ public CommandResponse Execute(string commandName, IDictionary<string, object> p
3436
{
3537
IsKeyboardShownCommand => IsKeyboardShown(parameters),
3638
HideKeyboardCommand => DismissKeyboard(parameters),
39+
PressEnterCommand => PressEnter(parameters),
3740
PressVolumeDownCommand => PressVolumeDown(parameters),
3841
PressVolumeUpCommand => PressVolumeUp(parameters),
3942
_ => CommandResponse.FailedEmptyResponse,
@@ -50,6 +53,11 @@ protected virtual CommandResponse DismissKeyboard(IDictionary<string, object> pa
5053
return CommandResponse.SuccessEmptyResponse;
5154
}
5255

56+
protected virtual CommandResponse PressEnter(IDictionary<string, object> parameters)
57+
{
58+
return CommandResponse.SuccessEmptyResponse;
59+
}
60+
5361
protected virtual CommandResponse PressVolumeDown(IDictionary<string, object> parameters)
5462
{
5563
return CommandResponse.SuccessEmptyResponse;

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ public class AppiumWindowsApp : AppiumApp, IWindowsApp
1010
public AppiumWindowsApp(Uri remoteAddress, IConfig config)
1111
: base(new WindowsDriver(remoteAddress, GetOptions(config)), config)
1212
{
13+
1314
}
1415

1516
public override ApplicationState AppState

src/TestUtils/src/UITest.Appium/HelperExtensions.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,15 @@ public static void PressVolumeDown(this IApp app)
358358
app.CommandExecutor.Execute("pressVolumeDown", ImmutableDictionary<string, object>.Empty);
359359
}
360360

361+
/// <summary>
362+
/// Presses the enter key in the app.
363+
/// </summary>
364+
/// <param name="app">Represents the main gateway to interact with an app.</param>
365+
public static void PressEnter(this IApp app)
366+
{
367+
app.CommandExecutor.Execute("pressEnter", ImmutableDictionary<string, object>.Empty);
368+
}
369+
361370
/// <summary>
362371
/// Performs a left to right swipe gesture on the screen.
363372
/// </summary>

0 commit comments

Comments
 (0)