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 DragCoordinates action to appium UITest #19333

Merged
merged 1 commit into from
Dec 11, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions src/TestUtils/src/UITest.Appium/Actions/AppiumPointerActions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,18 @@ public class AppiumPointerActions : ICommandExecutionGroup
const string DragAndDropCommand = "dragAndDrop";
const string ScrollToCommand = "scrollTo";
const string TapCoordinatesCommand = "tapCoordinates";
const string DragCoordinatesCommand = "dragCoordinates";

readonly AppiumApp _appiumApp;

readonly List<string> _commands = new()
{
ClickCommand,
DoubleClickCommand,
DragAndDropCommand,
ScrollToCommand,
TapCoordinatesCommand,
DragCoordinatesCommand
};

public AppiumPointerActions(AppiumApp appiumApp)
Expand All @@ -46,6 +49,7 @@ public CommandResponse Execute(string commandName, IDictionary<string, object> p
DragAndDropCommand => DragAndDrop(parameters),
ScrollToCommand => ScrollTo(parameters),
TapCoordinatesCommand => TapCoordinates(parameters),
DragCoordinatesCommand => DragCoordinates(parameters),
_ => CommandResponse.FailedEmptyResponse,
};
}
Expand Down Expand Up @@ -212,6 +216,29 @@ CommandResponse TapCoordinates(IDictionary<string, object> parameters)
return CommandResponse.FailedEmptyResponse;
}

CommandResponse DragCoordinates(IDictionary<string, object> parameters)
{
parameters.TryGetValue("fromX", out var fromX);
parameters.TryGetValue("fromY", out var fromY);

parameters.TryGetValue("toX", out var toX);
parameters.TryGetValue("toY", out var toY);

if (fromX is not null && fromY is not null && toX is not null && toY is not null)
{
DragCoordinates(
_appiumApp.Driver,
Convert.ToDouble(fromX),
Convert.ToDouble(fromY),
Convert.ToDouble(toX),
Convert.ToDouble(toY));

return CommandResponse.SuccessEmptyResponse;
}

return CommandResponse.FailedEmptyResponse;
}

static AppiumElement? GetAppiumElement(object element)
{
if (element is AppiumElement appiumElement)
Expand All @@ -235,5 +262,14 @@ static PointF ElementToClickablePoint(AppiumElement element)

return new PointF(x, y);
}

static void DragCoordinates(AppiumDriver driver, double fromX, double fromY, double toX, double toY)
{
new TouchAction(driver)
.Press(fromX, fromY)
.MoveTo(toX, toY)
.Release()
.Perform();
}
}
}
19 changes: 19 additions & 0 deletions src/TestUtils/src/UITest.Appium/HelperExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,25 @@ public static void SetSliderValue(this IApp app, string marked, double value, do
});
}

/// <summary>
/// Performs a continuous drag gesture between 2 points.
/// </summary>
/// <param name="app">Represents the main gateway to interact with an app.</param>
/// <param name="fromX">The x coordinate to start dragging from.</param>
/// <param name="fromY">The y coordinate to start dragging from.</param>
/// <param name="toX">The x coordinate to drag to.</param>
/// <param name="toY">The y coordinate to drag to.</param>
public static void DragCoordinates(this IApp app, float fromX, float fromY, float toX, float toY)
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("dragCoordinates", new Dictionary<string, object>
{
{ "fromX", fromX },
{ "fromY", fromY },
{ "toX", toX },
{ "toY", toY },
});
}

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