【问题标题】:Replacement for scrollTo and scrollToExact in java client v4.0java客户端v4.0中scrollTo和scrollToExact的替换
【发布时间】:2016-11-08 13:12:40
【问题描述】:

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

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

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

除了刷卡方法和其他可用方法 喜欢

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

有人知道替换scrollToscrollToExact 的任何可能方法吗?

【问题讨论】:

    标签: java android scroll appium swipe


    【解决方案1】:

    在 Appium 的讨论板上查看 this response

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

    【讨论】:

      【解决方案2】:

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

      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 - 元素的描述或文本滚动到

      回报:
      匹配的元素

      现在给用户swipe

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

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

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

      示例:

       @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);
       }
      

      这肯定适用于新版本的 Java Client 4.0 来执行您的 Appium 脚本

      问候:
      高拉夫小伙子

      【讨论】:

        猜你喜欢
        • 2016-04-23
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-12-08
        • 2017-01-17
        • 2014-12-13
        相关资源
        最近更新 更多