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

[Testing] Added methods to set the device orientation from UITests #19100

Merged
merged 1 commit into from Nov 30, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -0,0 +1,48 @@
using UITest.Core;

namespace UITest.Appium
{
public class AppiumOrientationActions : ICommandExecutionGroup
{
const string SetOrientationPortraitCommand = "setOrientationPortrait";
const string SetOrientationLandscapeCommand = "setOrientationLandscape";

protected readonly AppiumApp _app;

readonly List<string> _commands = new()
{
SetOrientationPortraitCommand,
SetOrientationLandscapeCommand,
};

public AppiumOrientationActions(AppiumApp app)
{
_app = app;
}

public bool IsCommandSupported(string commandName)
{
return _commands.Contains(commandName, StringComparer.OrdinalIgnoreCase);
}

public CommandResponse Execute(string commandName, IDictionary<string, object> parameters)
{
return commandName switch
{
SetOrientationPortraitCommand => SetOrientationPortrait(parameters),
SetOrientationLandscapeCommand => SetOrientationLandscape(parameters),
_ => CommandResponse.FailedEmptyResponse,
};
}

CommandResponse SetOrientationPortrait(IDictionary<string, object> parameters)
{
return new CommandResponse(_app.Driver.Orientation = OpenQA.Selenium.ScreenOrientation.Portrait, CommandResponseResult.Success);
}

CommandResponse SetOrientationLandscape(IDictionary<string, object> parameters)
{
return new CommandResponse(_app.Driver.Orientation = OpenQA.Selenium.ScreenOrientation.Landscape, CommandResponseResult.Success);
}
}
}
1 change: 1 addition & 0 deletions src/TestUtils/src/UITest.Appium/AppiumApp.cs
Expand Up @@ -21,6 +21,7 @@ public AppiumApp(AppiumDriver driver, IConfig config)
_commandExecutor.AddCommandGroup(new AppiumTextActions());
_commandExecutor.AddCommandGroup(new AppiumGeneralActions());
_commandExecutor.AddCommandGroup(new AppiumVirtualKeyboardActions(this));
_commandExecutor.AddCommandGroup(new AppiumOrientationActions(this));
}

public abstract ApplicationState AppState { get; }
Expand Down
18 changes: 18 additions & 0 deletions src/TestUtils/src/UITest.Appium/HelperExtensions.cs
Expand Up @@ -174,6 +174,24 @@ public static bool WaitForTextToBePresentInElement(this IApp app, string automat
}
}

/// <summary>
/// Changes the device orientation to landscape mode.
/// </summary>
/// <param name="app">Represents the main gateway to interact with an app.</param>
public static void SetOrientationLandscape(this IApp app)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

{
app.CommandExecutor.Execute("setOrientationLandscape", ImmutableDictionary<string, object>.Empty);
}

/// <summary>
/// Changes the device orientation to portrait mode.
/// </summary>
/// <param name="app">Represents the main gateway to interact with an app.</param>
public static void SetOrientationPortrait(this IApp app)
{
app.CommandExecutor.Execute("setOrientationPortrait", ImmutableDictionary<string, object>.Empty);
}

static IUIElement Wait(Func<IUIElement> query,
Func<IUIElement, bool> satisfactory,
string? timeoutMessage = null,
Expand Down