zoukankan      html  css  js  c++  java
  • Appium左右、上下滑动(Java)

    网上很多文章都说用swipe来左右滑动,你把代码一贴,结果报错,看半天,原来是java-client中swipe早就被废除了!!!下面介绍一种Java写法来左右上下滑动:

    首先,创建一个Swipe类

    import org.openqa.selenium.Dimension;
    
    import io.appium.java_client.TouchAction;
    import io.appium.java_client.android.AndroidDriver;
    import io.appium.java_client.touch.offset.PointOption;
    
    public class Swipe {
        // 上滑
        public void SwipeUp(AndroidDriver driver) {
            Dimension size = driver.manage().window().getSize();
            int height = size.height;
            int width = size.width;
            new TouchAction(driver).longPress(PointOption.point(width / 2, 100))
                    .moveTo(PointOption.point(width / 2, height - 100)).release()
                    .perform();
        }
    
        // 下滑
        public void SwipeDown(AndroidDriver driver) {
            Dimension size = driver.manage().window().getSize();
            int height = size.height;
            int width = size.width;
            new TouchAction(driver)
                    .longPress(PointOption.point(width / 2, height - 100))
                    .moveTo(PointOption.point(width / 2, 100)).release().perform();
        }
    
        // 左滑
        public void SwipeLeft(AndroidDriver driver) {
            Dimension size = driver.manage().window().getSize();
            int height = size.height;
            int width = size.width;
            new TouchAction(driver)
                    .longPress(PointOption.point(width - 100, height / 2))
                    .moveTo(PointOption.point(100, height / 2)).release().perform();
        }
    
        // 右滑
        public void SwipeRight(AndroidDriver driver) {
            Dimension size = driver.manage().window().getSize();
            int height = size.height;
            int width = size.width;
            new TouchAction(driver).longPress(PointOption.point(100, height / 2))
                    .moveTo(PointOption.point(width - 100, height / 2)).release()
                    .perform();
        }
    }
  • 相关阅读:
    Prometheus监控k8s集合
    docker集合
    开源堡垒机jumpserver
    ELK日志分析平台
    安全名称解释
    CPU上下文切换
    平均负载
    234. 回文链表
    125. 验证回文串
    122. 买卖股票的最佳时机II
  • 原文地址:https://www.cnblogs.com/wsy0202/p/11546085.html
Copyright © 2011-2022 走看看