java 客户端 v4.0 中 scrollTo 和 scrollToExact 的替换

Replacement for scrollTo and scrollToExact in java client v4.0

我正在使用 java 和 appium 为 Android/iOS 编写移动应用程序自动化测试用例。

我已经将我的 appium 版本从 3.1.0 升级到 4.0.0。现在我不能使用 scrollTo() 和 scrollToExact()

Java 客户端 ReadMe 自述文件内容如下:- scrollTo()scrollToExact() 已弃用。它们将在下一个版本中删除。

除滑动方法和 喜欢

((MobileElement)element).swipe(SwipeDirection.UP,100);

有谁知道替换 scrollToscrollToExact 的可能方法吗?

在 Appium 的讨论板上查看 this response

基本上,旧滚动方法的相同内容仍然可用(Android/iOS ui 自动程序);这只是意味着您可以创建自己的助手来满足您的精确需求。ui

此方法已弃用,因为它不一致,将被删除。这实际上是解决方法。
建议改用:

AppiumDriver.swipe(int, int, int, int, int)
MobileElement.swipe(SwipeElementDirection, int)   
MobileElement.swipe(SwipeElementDirection, int, int, int) 

或使用

搜索元素
MobileBy.ByAndroidUIAutomator

指定者:

scrollTo in interface ScrollsTo<org.openqa.selenium.WebElement>

参数:
text - 元素的描述或文本滚动到

Returns:
匹配

的元素

现在给用户 swipe

public abstract void swipe(int startx, int starty, int endx, int endy, int duration)

从界面复制的描述:
触摸快捷方式
在屏幕上滑动的便捷方法。

参数:
startx - 起始 x 坐标。
starty - 起始 y 坐标。
endx - 结束 x 坐标。
endy - 结束 y 坐标。
duration - 整个滑动动作的持续时间(以毫秒为单位)

示例:

 @Test
 public void swipingVertical() throws InterruptedException {
  //Get the size of screen.
  size = driver.manage().window().getSize();
  System.out.println(size);

  //Find swipe start and end point from screen's with and height.
  //Find starty point which is at bottom side of screen.
  int starty = (int) (size.height * 0.80);
  //Find endy point which is at top side of screen.
  int endy = (int) (size.height * 0.20);
  //Find horizontal point where you wants to swipe. It is in middle of screen width.
  int startx = size.width / 2;
  System.out.println("starty = " + starty + " ,endy = " + endy + " , startx = " + startx);

  //Swipe from Bottom to Top.
  driver.swipe(startx, starty, startx, endy, 3000);
  Thread.sleep(2000);
  //Swipe from Top to Bottom.
  driver.swipe(startx, endy, startx, starty, 3000);
  Thread.sleep(2000);
 }

新版JavaClient 4.0执行你的Appium Script肯定有效

问候:
高拉夫小伙子