You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

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 waitAction here 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 the moveTo action 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 swipe API 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, moveTo uses 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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.21 06:57:42