Skip to content
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

[UI Testing] Implement PressEnter method #22112

Merged
merged 3 commits into from
Apr 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions src/Controls/tests/UITests/Tests/Issues/Issue16386.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using NUnit.Framework;
using OpenQA.Selenium;
using UITest.Appium;
using UITest.Core;

Expand All @@ -20,13 +19,12 @@ public void HittingEnterKeySendsDone()
this.IgnoreIfPlatforms(new[]
{
TestDevice.Mac,
TestDevice.iOS,
TestDevice.Windows,
TestDevice.Windows
});

App.WaitForElement("HardwareEnterKeyEntry");
App.Tap("HardwareEnterKeyEntry");
App.SendKeys(66);
App.PressEnter();
App.WaitForElement("Success");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,19 @@ protected override CommandResponse DismissKeyboard(IDictionary<string, object> p
return CommandResponse.SuccessEmptyResponse;
}

protected override CommandResponse PressEnter(IDictionary<string, object> parameters)
{
if (_app.Driver is AndroidDriver android)
{
// 66 - KEYCODE_ENTER
// More information: https://developer.android.com/reference/android/view/KeyEvent.html
android.PressKeyCode(66);
return CommandResponse.SuccessEmptyResponse;
}

return CommandResponse.FailedEmptyResponse;
}

protected override CommandResponse PressVolumeDown(IDictionary<string, object> parameters)
{
if (_app.Driver is AndroidDriver android)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,23 @@ protected override CommandResponse DismissKeyboard(IDictionary<string, object> p
return CommandResponse.SuccessEmptyResponse;
}

protected override CommandResponse PressEnter(IDictionary<string, object> parameters)
{
try
{
if (_app.Driver.IsKeyboardShown())
{
_app.Driver.SwitchTo().ActiveElement().SendKeys(Keys.Return);
}
}
catch (InvalidElementStateException)
{
return CommandResponse.FailedEmptyResponse;
}

return CommandResponse.SuccessEmptyResponse;
}

protected override CommandResponse PressVolumeDown(IDictionary<string, object> parameters)
{
try
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ public class AppiumVirtualKeyboardActions : ICommandExecutionGroup
{
const string IsKeyboardShownCommand = "isKeyboardShown";
const string HideKeyboardCommand = "dismissKeyboard";
const string PressEnterCommand = "pressEnter";
const string PressVolumeDownCommand = "pressVolumeDown";
const string PressVolumeUpCommand = "pressVolumeUp";

Expand All @@ -14,6 +15,7 @@ public class AppiumVirtualKeyboardActions : ICommandExecutionGroup
{
IsKeyboardShownCommand,
HideKeyboardCommand,
PressEnterCommand,
PressVolumeDownCommand,
PressVolumeUpCommand,
};
Expand All @@ -34,6 +36,7 @@ public CommandResponse Execute(string commandName, IDictionary<string, object> p
{
IsKeyboardShownCommand => IsKeyboardShown(parameters),
HideKeyboardCommand => DismissKeyboard(parameters),
PressEnterCommand => PressEnter(parameters),
PressVolumeDownCommand => PressVolumeDown(parameters),
PressVolumeUpCommand => PressVolumeUp(parameters),
_ => CommandResponse.FailedEmptyResponse,
Expand All @@ -50,6 +53,11 @@ protected virtual CommandResponse DismissKeyboard(IDictionary<string, object> pa
return CommandResponse.SuccessEmptyResponse;
}

protected virtual CommandResponse PressEnter(IDictionary<string, object> parameters)
{
return CommandResponse.SuccessEmptyResponse;
}

protected virtual CommandResponse PressVolumeDown(IDictionary<string, object> parameters)
{
return CommandResponse.SuccessEmptyResponse;
Expand Down
1 change: 1 addition & 0 deletions src/TestUtils/src/UITest.Appium/AppiumWindowsApp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public class AppiumWindowsApp : AppiumApp, IWindowsApp
public AppiumWindowsApp(Uri remoteAddress, IConfig config)
: base(new WindowsDriver(remoteAddress, GetOptions(config)), config)
{

}

public override ApplicationState AppState
Expand Down
9 changes: 9 additions & 0 deletions src/TestUtils/src/UITest.Appium/HelperExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,15 @@ public static void PressVolumeDown(this IApp app)
app.CommandExecutor.Execute("pressVolumeDown", ImmutableDictionary<string, object>.Empty);
}

/// <summary>
/// Presses the enter key in the app.
/// </summary>
/// <param name="app">Represents the main gateway to interact with an app.</param>
public static void PressEnter(this IApp app)
{
app.CommandExecutor.Execute("pressEnter", ImmutableDictionary<string, object>.Empty);
}

/// <summary>
/// Performs a left to right swipe gesture on the screen.
/// </summary>
Expand Down
Loading