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

Update files to match .NET MAUI implementation #13

Merged
merged 3 commits into from
May 14, 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
using OpenQA.Selenium.Appium;
using Plugin.Maui.UITestHelpers.Core;

namespace Plugin.Maui.UITestHelpers.Appium
{
public class AppiumCatalystMouseActions : ICommandExecutionGroup
{
const string DoubleClickCommand = "doubleClick";

readonly List<string> _commands = new()
{
DoubleClickCommand,
};
readonly AppiumApp _appiumApp;

public AppiumCatalystMouseActions(AppiumApp appiumApp)
{
_appiumApp = appiumApp;
}

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

public CommandResponse Execute(string commandName, IDictionary<string, object> parameters)
{
return commandName switch
{
DoubleClickCommand => DoubleClick(parameters),
_ => CommandResponse.FailedEmptyResponse,
};
}

CommandResponse DoubleClick(IDictionary<string, object> parameters)
{
var element = GetAppiumElement(parameters["element"]);

if (element != null)
{
_appiumApp.Driver.ExecuteScript("macos: doubleClick", new Dictionary<string, object>
{
{ "elementId", element.Id },
});
}
return CommandResponse.SuccessEmptyResponse;
}

static AppiumElement? GetAppiumElement(object element)
{
if (element is AppiumElement appiumElement)
{
return appiumElement;
}
else if (element is AppiumDriverElement driverElement)
{
return driverElement.AppiumElement;
}

return null;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@

namespace Plugin.Maui.UITestHelpers.Appium
{
public class AppiumCatalystPointerActions : ICommandExecutionGroup
public class AppiumCatalystTouchActions : ICommandExecutionGroup
{
const string DoubleClickCommand = "doubleClick";
const string DoubleTapCommand = "doubleTap";
const string DragAndDropCommand = "dragAndDrop";

readonly List<string> _commands = new()
{
DoubleClickCommand,
DoubleTapCommand,
DragAndDropCommand,
};
readonly AppiumApp _appiumApp;

public AppiumCatalystPointerActions(AppiumApp appiumApp)
public AppiumCatalystTouchActions(AppiumApp appiumApp)
{
_appiumApp = appiumApp;
}
Expand All @@ -29,13 +29,13 @@ public CommandResponse Execute(string commandName, IDictionary<string, object> p
{
return commandName switch
{
DoubleClickCommand => DoubleClick(parameters),
DoubleTapCommand => DoubleTap(parameters),
DragAndDropCommand => DragAndDrop(parameters),
_ => CommandResponse.FailedEmptyResponse,
};
}

CommandResponse DoubleClick(IDictionary<string, object> parameters)
CommandResponse DoubleTap(IDictionary<string, object> parameters)
{
var element = GetAppiumElement(parameters["element"]);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
using OpenQA.Selenium.Appium;
using Plugin.Maui.UITestHelpers.Core;


namespace Plugin.Maui.UITestHelpers.Appium
{
public class AppiumIOSMouseActions : ICommandExecutionGroup
{
const string DoubleClickCommand = "doubleClick";

readonly List<string> _commands = new()
{
DoubleClickCommand,
};
readonly AppiumApp _appiumApp;

public AppiumIOSMouseActions(AppiumApp appiumApp)
{
_appiumApp = appiumApp;
}

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

public CommandResponse Execute(string commandName, IDictionary<string, object> parameters)
{
return commandName switch
{
DoubleClickCommand => DoubleClick(parameters),
_ => CommandResponse.FailedEmptyResponse,
};
}

CommandResponse DoubleClick(IDictionary<string, object> parameters)
{
var element = GetAppiumElement(parameters["element"]);

if (element != null)
{
_appiumApp.Driver.ExecuteScript("mobile: doubleTap", new Dictionary<string, object>
{
{ "elementId", element.Id },
});
}

return CommandResponse.SuccessEmptyResponse;
}

static AppiumElement? GetAppiumElement(object element)
{
if (element is AppiumElement appiumElement)
{
return appiumElement;
}
else if (element is AppiumDriverElement driverElement)
{
return driverElement.AppiumElement;
}

return null;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@

namespace Plugin.Maui.UITestHelpers.Appium
{
public class AppiumIOSPointerActions : ICommandExecutionGroup
public class AppiumIOSTouchActions : ICommandExecutionGroup
{
const string DoubleClickCommand = "doubleClick";
const string DoubleTapCommand = "doubleTap";
const string DragAndDropCommand = "dragAndDrop";

readonly List<string> _commands = new()
{
DoubleClickCommand,
DoubleTapCommand,
DragAndDropCommand
};
readonly AppiumApp _appiumApp;

public AppiumIOSPointerActions(AppiumApp appiumApp)
public AppiumIOSTouchActions(AppiumApp appiumApp)
{
_appiumApp = appiumApp;
}
Expand All @@ -29,13 +29,13 @@ public CommandResponse Execute(string commandName, IDictionary<string, object> p
{
return commandName switch
{
DoubleClickCommand => DoubleClick(parameters),
DoubleTapCommand => DoubleTap(parameters),
DragAndDropCommand => DragAndDrop(parameters),
_ => CommandResponse.FailedEmptyResponse,
};
}

CommandResponse DoubleClick(IDictionary<string, object> parameters)
CommandResponse DoubleTap(IDictionary<string, object> parameters)
{
var element = GetAppiumElement(parameters["element"]);

Expand Down
Loading