Appium Java Client 6.0.0指定时长滑动实现的疑问
Handling Swipe Actions in Appium Java Client 6.0.0+
Starting with Appium Java Client 6.0.0, the old driver.swipe(fromX, toX, fromY, toY, duration) API was removed entirely. To implement swipe gestures now, you have to use the TouchAction class instead. Here's the standard example code for this approach:
(new TouchAction(driver)) .press(PointOption.point(fromX, fromY)) .waitAction(WaitOptions.waitOptions(Duration.ofMillis(1000))) .moveTo(PointOption.point(offsetX, offsetY)) .release() .perform();
But from my experience working with this implementation, there are notable flaws when it comes to swipe duration logic:
- The
waitActionhere only adds a static pause after pressing down on the starting point—it doesn't actually control the duration of the swipe movement itself. The time taken for themoveToaction is handled internally by Appium, and can vary across different devices, OS versions, or even Appium server setups. - This means we lose the precise, consistent duration control that the original
swipeAPI provided. For test cases that rely on specific swipe speeds (like validating scroll animations or gesture-triggered features), this inconsistency often leads to flaky, unreliable results. - On top of that,
moveTouses offset values relative to the initial press point, which is a shift from the old API's absolute end coordinates. You have to manually calculate offsets (e.g.,offsetX = toX - fromX,offsetY = toY - fromY), adding unnecessary boilerplate code to your tests.
If you need more reliable control over gesture timing, exploring the PointerInput and Sequence classes (available in newer Appium versions) is a better bet—they offer far more granular control over how gestures are executed.
内容的提问来源于stack exchange,提问作者Adrian Theodorescu
相关产品推荐
相关产品推荐

