Added lifecycle methods to UITest (#19102)
Co-authored-by: Gerald Versluis <gerald.versluis@microsoft.com>
This commit is contained in:
Родитель
174a3a9ef6
Коммит
7c54927001
|
@ -0,0 +1,84 @@
|
|||
using UITest.Core;
|
||||
|
||||
namespace UITest.Appium
|
||||
{
|
||||
public class AppiumLifecycleActions : ICommandExecutionGroup
|
||||
{
|
||||
const string LaunchAppCommand = "launchApp";
|
||||
const string BackgroundAppCommand = "backgroundApp";
|
||||
const string ResetAppCommand = "resetApp";
|
||||
const string CloseAppCommand = "closeApp";
|
||||
|
||||
protected readonly AppiumApp _app;
|
||||
|
||||
readonly List<string> _commands = new()
|
||||
{
|
||||
LaunchAppCommand,
|
||||
BackgroundAppCommand,
|
||||
ResetAppCommand,
|
||||
CloseAppCommand,
|
||||
};
|
||||
|
||||
public AppiumLifecycleActions(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
|
||||
{
|
||||
LaunchAppCommand => LaunchApp(parameters),
|
||||
BackgroundAppCommand => BackgroundApp(parameters),
|
||||
ResetAppCommand => ResetApp(parameters),
|
||||
CloseAppCommand => CloseApp(parameters),
|
||||
_ => CommandResponse.FailedEmptyResponse,
|
||||
};
|
||||
}
|
||||
|
||||
CommandResponse LaunchApp(IDictionary<string, object> parameters)
|
||||
{
|
||||
if (_app?.Driver is null)
|
||||
return CommandResponse.FailedEmptyResponse;
|
||||
|
||||
_app.Driver.LaunchApp();
|
||||
|
||||
return CommandResponse.SuccessEmptyResponse;
|
||||
}
|
||||
|
||||
CommandResponse BackgroundApp(IDictionary<string, object> parameters)
|
||||
{
|
||||
if (_app?.Driver is null)
|
||||
return CommandResponse.FailedEmptyResponse;
|
||||
|
||||
_app.Driver.BackgroundApp();
|
||||
|
||||
return CommandResponse.SuccessEmptyResponse;
|
||||
}
|
||||
|
||||
CommandResponse ResetApp(IDictionary<string, object> parameters)
|
||||
{
|
||||
if (_app?.Driver is null)
|
||||
return CommandResponse.FailedEmptyResponse;
|
||||
|
||||
_app.Driver.ResetApp();
|
||||
|
||||
return CommandResponse.SuccessEmptyResponse;
|
||||
}
|
||||
|
||||
CommandResponse CloseApp(IDictionary<string, object> parameters)
|
||||
{
|
||||
if (_app?.Driver is null)
|
||||
return CommandResponse.FailedEmptyResponse;
|
||||
|
||||
_app.Driver.CloseApp();
|
||||
|
||||
return CommandResponse.SuccessEmptyResponse;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -25,6 +25,7 @@ namespace UITest.Appium
|
|||
_commandExecutor.AddCommandGroup(new AppiumSwipeActions(this));
|
||||
_commandExecutor.AddCommandGroup(new AppiumScrollActions(this));
|
||||
_commandExecutor.AddCommandGroup(new AppiumOrientationActions(this));
|
||||
_commandExecutor.AddCommandGroup(new AppiumLifecycleActions(this));
|
||||
}
|
||||
|
||||
public abstract ApplicationState AppState { get; }
|
||||
|
|
|
@ -395,6 +395,43 @@ namespace UITest.Appium
|
|||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Executes an existing application on the device.
|
||||
/// If the application is already running then it will be brought to the foreground.
|
||||
/// </summary>
|
||||
/// <param name="app">Represents the main gateway to interact with an app.</param>
|
||||
public static void LaunchApp(this IApp app)
|
||||
{
|
||||
app.CommandExecutor.Execute("launchApp", ImmutableDictionary<string, object>.Empty);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Send the currently running app for this session to the background.
|
||||
/// </summary>
|
||||
/// <param name="app">Represents the main gateway to interact with an app.</param>
|
||||
public static void BackgroundApp(this IApp app)
|
||||
{
|
||||
app.CommandExecutor.Execute("backgroundApp", ImmutableDictionary<string, object>.Empty);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reset the currently running app for this session.
|
||||
/// </summary>
|
||||
/// <param name="app">Represents the main gateway to interact with an app.</param>
|
||||
public static void ResetApp(this IApp app)
|
||||
{
|
||||
app.CommandExecutor.Execute("resetApp", ImmutableDictionary<string, object>.Empty);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Close an app on device.
|
||||
/// </summary>
|
||||
/// <param name="app">Represents the main gateway to interact with an app.</param>
|
||||
public static void CloseApp(this IApp app)
|
||||
{
|
||||
app.CommandExecutor.Execute("closeApp", ImmutableDictionary<string, object>.Empty);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the value of a Slider element that matches marked.
|
||||
/// </summary>
|
||||
|
|
Загрузка…
Ссылка в новой задаче