From 3d4ae31601ffeec7f62d07a1de9fb4b9a2f1336e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20Su=C3=A1rez?= Date: Tue, 28 Jan 2025 20:27:25 +0100 Subject: [PATCH 1/4] Implement Appium swipe actions using Mac Driver on Catalyst --- .../Actions/AppiumCatalystSwipeActions.cs | 65 +++++++++++++++++++ .../Actions/AppiumSwipeActions.cs | 4 +- .../src/UITest.Appium/AppiumCatalystApp.cs | 1 + 3 files changed, 68 insertions(+), 2 deletions(-) create mode 100644 src/TestUtils/src/UITest.Appium/Actions/AppiumCatalystSwipeActions.cs 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..38af4d59ec0f --- /dev/null +++ b/src/TestUtils/src/UITest.Appium/Actions/AppiumCatalystSwipeActions.cs @@ -0,0 +1,65 @@ +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 y = (int)(position.X + (size.Width * swipePercentage)); + int x = position.Y + size.Height / 2; + + var parameters = new Dictionary + { + { "x" , x }, + { "y" , y }, + { "direction" , "right" }, + { "velocity" , swipeSpeed }, + + }; + + if (element is not null) + { + // The internal element identifier to swipe on. + // If both are set then x and y are considered as relative element coordinates. + // If only x and y are set then these are parsed as absolute coordinates. + parameters.Add("elementId", element.Id); + } + + driver.ExecuteScript("mobile: swipe", 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 x = (int)(position.X + (size.Width * 0.05)); + int y = position.Y + size.Height / 2; + + var parameters = new Dictionary + { + { "x" , x }, + { "y" , y }, + { "direction" , "left" }, + { "velocity" , swipeSpeed }, + + }; + + if (element is not null) + { + // The internal element identifier to swipe on. + // If both are set then x and y are considered as relative element coordinates. + // If only x and y are set then these are parsed as absolute coordinates. + parameters.Add("elementId", element.Id); + } + + driver.ExecuteScript("mobile: swipe", 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)); } From b5d6180299a51618125e8a6f9fb6dc9f77569133 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20Su=C3=A1rez?= Date: Tue, 28 Jan 2025 20:58:07 +0100 Subject: [PATCH 2/4] Updated impl --- .../Actions/AppiumCatalystSwipeActions.cs | 56 +++++++++---------- 1 file changed, 26 insertions(+), 30 deletions(-) diff --git a/src/TestUtils/src/UITest.Appium/Actions/AppiumCatalystSwipeActions.cs b/src/TestUtils/src/UITest.Appium/Actions/AppiumCatalystSwipeActions.cs index 38af4d59ec0f..8e59f9c2b068 100644 --- a/src/TestUtils/src/UITest.Appium/Actions/AppiumCatalystSwipeActions.cs +++ b/src/TestUtils/src/UITest.Appium/Actions/AppiumCatalystSwipeActions.cs @@ -11,27 +11,25 @@ protected override void SwipeToRight(AppiumDriver driver, AppiumElement? element 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 y = (int)(position.X + (size.Width * swipePercentage)); - int x = position.Y + size.Height / 2; + 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 { - { "x" , x }, - { "y" , y }, - { "direction" , "right" }, - { "velocity" , swipeSpeed }, - + { "startX" , startX }, + { "startY" , startY }, + { "endX" , endX }, + { "endY" , endY }, + { "duration" , swipeSpeed }, }; if (element is not null) - { - // The internal element identifier to swipe on. - // If both are set then x and y are considered as relative element coordinates. - // If only x and y are set then these are parsed as absolute coordinates. - parameters.Add("elementId", element.Id); - } - - driver.ExecuteScript("mobile: swipe", parameters); + parameters.Add("sourceElementId", element.Id); + + driver.ExecuteScript("macos: clickAndDrag", parameters); } protected override void SwipeToLeft(AppiumDriver driver, AppiumElement? element, double swipePercentage, int swipeSpeed, bool withInertia = true) @@ -39,27 +37,25 @@ protected override void SwipeToLeft(AppiumDriver driver, AppiumElement? element, 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 x = (int)(position.X + (size.Width * 0.05)); - int y = position.Y + size.Height / 2; + 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 { - { "x" , x }, - { "y" , y }, - { "direction" , "left" }, - { "velocity" , swipeSpeed }, - + { "startX" , startX }, + { "startY" , startY }, + { "endX" , endX }, + { "endY" , endY }, + { "duration" , swipeSpeed }, }; if (element is not null) - { - // The internal element identifier to swipe on. - // If both are set then x and y are considered as relative element coordinates. - // If only x and y are set then these are parsed as absolute coordinates. - parameters.Add("elementId", element.Id); - } - - driver.ExecuteScript("mobile: swipe", parameters); + parameters.Add("sourceElementId", element.Id); + + driver.ExecuteScript("macos: pressAndDrag", parameters); } } } \ No newline at end of file From f522a7d03f8e35e314e9d90344bbf9515d797fe0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20Su=C3=A1rez?= Date: Tue, 28 Jan 2025 20:58:34 +0100 Subject: [PATCH 3/4] Updated test --- .../tests/TestCases.Shared.Tests/Tests/Issues/Issue9306.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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; From 1e450469d5d61ec54ad21befc0037b1679053a72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20Sua=CC=81rez?= Date: Wed, 29 Jan 2025 12:08:13 +0100 Subject: [PATCH 4/4] Updated impl --- .../Actions/AppiumCatalystSwipeActions.cs | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/src/TestUtils/src/UITest.Appium/Actions/AppiumCatalystSwipeActions.cs b/src/TestUtils/src/UITest.Appium/Actions/AppiumCatalystSwipeActions.cs index 8e59f9c2b068..ca0022c24bd0 100644 --- a/src/TestUtils/src/UITest.Appium/Actions/AppiumCatalystSwipeActions.cs +++ b/src/TestUtils/src/UITest.Appium/Actions/AppiumCatalystSwipeActions.cs @@ -23,12 +23,9 @@ protected override void SwipeToRight(AppiumDriver driver, AppiumElement? element { "startY" , startY }, { "endX" , endX }, { "endY" , endY }, - { "duration" , swipeSpeed }, + { "duration" , 0.5 }, }; - if (element is not null) - parameters.Add("sourceElementId", element.Id); - driver.ExecuteScript("macos: clickAndDrag", parameters); } @@ -49,11 +46,8 @@ protected override void SwipeToLeft(AppiumDriver driver, AppiumElement? element, { "startY" , startY }, { "endX" , endX }, { "endY" , endY }, - { "duration" , swipeSpeed }, + { "duration" , 0.5 }, }; - - if (element is not null) - parameters.Add("sourceElementId", element.Id); driver.ExecuteScript("macos: pressAndDrag", parameters); }