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] Implement Appium swipe action on Catalyst using the Mac Driver #27441

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
@@ -1,4 +1,4 @@
#if IOS
#if IOS || MACCATALYST
using NUnit.Framework;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Test enabled on Catalyst just to validate the changes added.

using NUnit.Framework.Legacy;
using UITest.Appium;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
using OpenQA.Selenium.Appium;

namespace UITest.Appium
{
public class AppiumCatalystSwipeActions : AppiumSwipeActions
{
public AppiumCatalystSwipeActions(AppiumApp appiumApp) : base(appiumApp) { }

protected override void SwipeToRight(AppiumDriver driver, AppiumElement? element, double swipePercentage, int swipeSpeed, bool withInertia = true)
{
var position = element is not null ? element.Location : System.Drawing.Point.Empty;
var size = element is not null ? element.Size : driver.Manage().Window.Size;

int startX = (int)(position.X + (size.Width * 0.05));
int startY = position.Y + size.Height / 2;

int endX = (int)(position.X + (size.Width * swipePercentage));
int endY = startY;

var parameters = new Dictionary<string, object>
{
{ "startX" , startX },
{ "startY" , startY },
{ "endX" , endX },
{ "endY" , endY },
{ "duration" , 0.5 },
};

driver.ExecuteScript("macos: clickAndDrag", parameters);
}

protected override void SwipeToLeft(AppiumDriver driver, AppiumElement? element, double swipePercentage, int swipeSpeed, bool withInertia = true)
{
var position = element is not null ? element.Location : System.Drawing.Point.Empty;
var size = element is not null ? element.Size : driver.Manage().Window.Size;

int startX = (int)(position.X + (size.Width * swipePercentage));
int startY = position.Y + size.Height / 2;

int endX = (int)(position.X + (size.Width * 0.05));
int endY = startY;

var parameters = new Dictionary<string, object>
{
{ "startX" , startX },
{ "startY" , startY },
{ "endX" , endX },
{ "endY" , endY },
{ "duration" , 0.5 },
};

driver.ExecuteScript("macos: pressAndDrag", parameters);
jsuarezruiz marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ CommandResponse SwipeRightToLeft(IDictionary<string, object> parameters)
return null;
}

static void SwipeToRight(AppiumDriver driver, AppiumElement? element, double swipePercentage, int swipeSpeed, bool withInertia = true)
virtual protected void SwipeToRight(AppiumDriver driver, AppiumElement? element, double swipePercentage, int swipeSpeed, bool withInertia = true)
{
var position = element is not null ? element.Location : System.Drawing.Point.Empty;
var size = element is not null ? element.Size : driver.Manage().Window.Size;
Expand All @@ -100,7 +100,7 @@ static void SwipeToRight(AppiumDriver driver, AppiumElement? element, double swi
driver.PerformActions([swipeSequence]);
}

static void SwipeToLeft(AppiumDriver driver, AppiumElement? element, double swipePercentage, int swipeSpeed, bool withInertia = true)
virtual protected void SwipeToLeft(AppiumDriver driver, AppiumElement? element, double swipePercentage, int swipeSpeed, bool withInertia = true)
{
var position = element is not null ? element.Location : System.Drawing.Point.Empty;
var size = element is not null ? element.Size : driver.Manage().Window.Size;
Expand Down
1 change: 1 addition & 0 deletions src/TestUtils/src/UITest.Appium/AppiumCatalystApp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public AppiumCatalystApp(Uri remoteAddress, IConfig config)
_commandExecutor.AddCommandGroup(new AppiumCatalystTouchActions(this));
_commandExecutor.AddCommandGroup(new AppiumCatalystAlertActions(this));
_commandExecutor.AddCommandGroup(new AppiumCatalystSpecificActions(this));
_commandExecutor.AddCommandGroup(new AppiumCatalystSwipeActions(this));
_commandExecutor.AddCommandGroup(new AppiumCatalystVirtualKeyboardActions(this));
_commandExecutor.AddCommandGroup(new AppiumCatalystScrollActions(this));
}
Expand Down
Loading