Skip to content

Commit

Permalink
- rework scroll a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
PureWeen committed May 7, 2024
1 parent d3a9596 commit 30a7bb4
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 32 deletions.
2 changes: 1 addition & 1 deletion src/Controls/tests/UITests/Tests/Issues/Issue18716.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public Issue18716(TestDevice device)
[Category(UITestCategories.WebView)]
public async Task CanScrollWebView()
{
this.IgnoreIfPlatforms(new TestDevice[] { TestDevice.Android, TestDevice.Mac, TestDevice.Windows });
this.IgnoreIfPlatforms(new TestDevice[] { TestDevice.Android, TestDevice.Windows, TestDevice.iOS });

await Task.Delay(1000); // Wait WebView to load.

Expand Down
60 changes: 29 additions & 31 deletions src/TestUtils/src/UITest.Appium/Actions/AppiumScrollActions.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using OpenQA.Selenium.Appium;
using OpenQA.Selenium.Appium.Interactions;
using OpenQA.Selenium.Appium.Mac;
using OpenQA.Selenium.Appium.MultiTouch;
using OpenQA.Selenium.Interactions;
using UITest.Core;
Expand Down Expand Up @@ -151,15 +152,7 @@ static void ScrollToLeft(AppiumDriver driver, AppiumElement element, ScrollStrat

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

OpenQA.Selenium.Appium.Interactions.PointerInputDevice touchDevice = new OpenQA.Selenium.Appium.Interactions.PointerInputDevice(PointerKind.Touch);
var scrollSequence = new ActionSequence(touchDevice, 0);
scrollSequence.AddAction(touchDevice.CreatePointerMove(CoordinateOrigin.Viewport, startX, startY, TimeSpan.Zero));
scrollSequence.AddAction(touchDevice.CreatePointerDown(PointerButton.TouchContact));
scrollSequence.AddAction(touchDevice.CreatePause(TimeSpan.FromMilliseconds(ScrollTouchDownTime)));
scrollSequence.AddAction(touchDevice.CreatePointerMove(CoordinateOrigin.Viewport, endX, endY, TimeSpan.FromMilliseconds(strategy != ScrollStrategy.Programmatically ? swipeSpeed : ProgrammaticallyScrollTime)));
scrollSequence.AddAction(touchDevice.CreatePointerUp(PointerButton.TouchContact));
driver.PerformActions([scrollSequence]);
PerformActions(driver, startX, startY, endX, endY, strategy, swipeSpeed);
}

static void ScrollToDown(AppiumDriver driver, AppiumElement element, ScrollStrategy strategy, double swipePercentage, int swipeSpeed, bool withInertia = true)
Expand All @@ -172,15 +165,7 @@ static void ScrollToDown(AppiumDriver driver, AppiumElement element, ScrollStrat

int endX = startX;
int endY = (int)(position.Y + (size.Height * 0.05));

OpenQA.Selenium.Appium.Interactions.PointerInputDevice touchDevice = new OpenQA.Selenium.Appium.Interactions.PointerInputDevice(PointerKind.Touch);
var scrollSequence = new ActionSequence(touchDevice, 0);
scrollSequence.AddAction(touchDevice.CreatePointerMove(CoordinateOrigin.Viewport, startX, startY, TimeSpan.Zero));
scrollSequence.AddAction(touchDevice.CreatePointerDown(PointerButton.TouchContact));
scrollSequence.AddAction(touchDevice.CreatePause(TimeSpan.FromMilliseconds(ScrollTouchDownTime)));
scrollSequence.AddAction(touchDevice.CreatePointerMove(CoordinateOrigin.Viewport, endX, endY, TimeSpan.FromMilliseconds(strategy != ScrollStrategy.Programmatically ? swipeSpeed : ProgrammaticallyScrollTime)));
scrollSequence.AddAction(touchDevice.CreatePointerUp(PointerButton.TouchContact));
driver.PerformActions([scrollSequence]);
PerformActions(driver, startX, startY, endX, endY, strategy, swipeSpeed);
}

static void ScrollToRight(AppiumDriver driver, AppiumElement element, ScrollStrategy strategy, double swipePercentage, int swipeSpeed, bool withInertia = true)
Expand All @@ -193,15 +178,7 @@ static void ScrollToRight(AppiumDriver driver, AppiumElement element, ScrollStra

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

OpenQA.Selenium.Appium.Interactions.PointerInputDevice touchDevice = new OpenQA.Selenium.Appium.Interactions.PointerInputDevice(PointerKind.Touch);
var scrollSequence = new ActionSequence(touchDevice, 0);
scrollSequence.AddAction(touchDevice.CreatePointerMove(CoordinateOrigin.Viewport, startX, startY, TimeSpan.Zero));
scrollSequence.AddAction(touchDevice.CreatePointerDown(PointerButton.TouchContact));
scrollSequence.AddAction(touchDevice.CreatePause(TimeSpan.FromMilliseconds(ScrollTouchDownTime)));
scrollSequence.AddAction(touchDevice.CreatePointerMove(CoordinateOrigin.Viewport, endX, endY, TimeSpan.FromMilliseconds(strategy != ScrollStrategy.Programmatically ? swipeSpeed : ProgrammaticallyScrollTime)));
scrollSequence.AddAction(touchDevice.CreatePointerUp(PointerButton.TouchContact));
driver.PerformActions([scrollSequence]);
PerformActions(driver, startX, startY, endX, endY, strategy, swipeSpeed);
}

static void ScrollToUp(AppiumDriver driver, AppiumElement element, ScrollStrategy strategy, double swipePercentage, int swipeSpeed, bool withInertia = true)
Expand All @@ -214,13 +191,34 @@ static void ScrollToUp(AppiumDriver driver, AppiumElement element, ScrollStrateg

int endX = startX;
int endY = (int)(position.Y + (size.Height * swipePercentage));
PerformActions(driver, startX, startY, endX, endY, strategy, swipeSpeed);
}

static void PerformActions(
AppiumDriver driver,
int startX,
int startY,
int endX,
int endY,
ScrollStrategy strategy,
int swipeSpeed)
{

OpenQA.Selenium.Appium.Interactions.PointerInputDevice touchDevice = new OpenQA.Selenium.Appium.Interactions.PointerInputDevice(PointerKind.Touch);
var pointerKind = PointerKind.Touch;
if (driver is MacDriver)
{
pointerKind = PointerKind.Mouse;
}

OpenQA.Selenium.Appium.Interactions.PointerInputDevice touchDevice = new OpenQA.Selenium.Appium.Interactions.PointerInputDevice(pointerKind);
var scrollSequence = new ActionSequence(touchDevice, 0);
scrollSequence.AddAction(touchDevice.CreatePointerMove(CoordinateOrigin.Viewport, startX, startY, TimeSpan.Zero));
scrollSequence.AddAction(touchDevice.CreatePointerMove(CoordinateOrigin.Viewport, startX, startY, TimeSpan.FromMilliseconds(2)));
scrollSequence.AddAction(touchDevice.CreatePointerDown(PointerButton.TouchContact));
scrollSequence.AddAction(touchDevice.CreatePause(TimeSpan.FromMilliseconds(ScrollTouchDownTime)));
scrollSequence.AddAction(touchDevice.CreatePointerMove(CoordinateOrigin.Viewport, endX, endY, TimeSpan.FromMilliseconds(strategy != ScrollStrategy.Programmatically ? swipeSpeed : ProgrammaticallyScrollTime)));
scrollSequence.AddAction(touchDevice.CreatePause(TimeSpan.FromMilliseconds(Math.Max(ScrollTouchDownTime, 2))));

var moveDuration = TimeSpan.FromMilliseconds(Math.Max(2, strategy != ScrollStrategy.Programmatically ? swipeSpeed : ProgrammaticallyScrollTime));
scrollSequence.AddAction(touchDevice.CreatePointerMove(CoordinateOrigin.Viewport, endX, endY, moveDuration));

scrollSequence.AddAction(touchDevice.CreatePointerUp(PointerButton.TouchContact));
driver.PerformActions([scrollSequence]);
}
Expand Down

0 comments on commit 30a7bb4

Please sign in to comment.