diff --git a/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue9306.cs b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue9306.cs index 72234c7a21f8..a651023e4f2b 100644 --- a/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue9306.cs +++ b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue9306.cs @@ -1,4 +1,4 @@ -#if IOS +#if IOS || MACCATALYST using NUnit.Framework; using NUnit.Framework.Legacy; using UITest.Appium; diff --git a/src/TestUtils/src/UITest.Appium/Actions/AppiumCatalystSwipeActions.cs b/src/TestUtils/src/UITest.Appium/Actions/AppiumCatalystSwipeActions.cs new file mode 100644 index 000000000000..ca0022c24bd0 --- /dev/null +++ b/src/TestUtils/src/UITest.Appium/Actions/AppiumCatalystSwipeActions.cs @@ -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 + { + { "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 + { + { "startX" , startX }, + { "startY" , startY }, + { "endX" , endX }, + { "endY" , endY }, + { "duration" , 0.5 }, + }; + + driver.ExecuteScript("macos: pressAndDrag", parameters); + } + } +} \ No newline at end of file diff --git a/src/TestUtils/src/UITest.Appium/Actions/AppiumSwipeActions.cs b/src/TestUtils/src/UITest.Appium/Actions/AppiumSwipeActions.cs index 09f0fe8a3698..c068de8bdc6d 100644 --- a/src/TestUtils/src/UITest.Appium/Actions/AppiumSwipeActions.cs +++ b/src/TestUtils/src/UITest.Appium/Actions/AppiumSwipeActions.cs @@ -80,7 +80,7 @@ CommandResponse SwipeRightToLeft(IDictionary 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; @@ -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; diff --git a/src/TestUtils/src/UITest.Appium/AppiumCatalystApp.cs b/src/TestUtils/src/UITest.Appium/AppiumCatalystApp.cs index 331463c885a5..c60da6fdf6d2 100644 --- a/src/TestUtils/src/UITest.Appium/AppiumCatalystApp.cs +++ b/src/TestUtils/src/UITest.Appium/AppiumCatalystApp.cs @@ -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)); }