zoukankan      html  css  js  c++  java
  • Appium 之上划、下划,左划、右划

    听说appium Java-client 新版本不支持swipe了,网上没找到完整可用的,今天正好整理出用TouchAction替换的脚本,记录一下,嘻嘻……

    import java.time.Duration;
    
    import io.appium.java_client.TouchAction;
    import io.appium.java_client.android.AndroidDriver;
    import io.appium.java_client.touch.WaitOptions;
    import io.appium.java_client.touch.offset.PointOption;
    
    public class SwipeClass {
        
        static Duration duration=Duration.ofSeconds(1);
        public void swipeToUp(AndroidDriver driver) {
            int width = driver.manage().window().getSize().width;
            int height = driver.manage().window().getSize().height;
            TouchAction action1=new TouchAction(driver).press(PointOption.point(width/2, height*3/4)).waitAction(WaitOptions.waitOptions(duration))
                                    .moveTo(PointOption.point(width/2, height/4)).release();
            action1.perform();
        }
    
     
        public void swipeToDown(AndroidDriver driver) {
            int width = driver.manage().window().getSize().width;
            int height = driver.manage().window().getSize().height;
            TouchAction action2=new TouchAction(driver).press(PointOption.point(width/2, height/4)).waitAction(WaitOptions.waitOptions(duration))
                                    .moveTo(PointOption.point(width/2, height*3/4)).release();
            action2.perform();
        }
    
        public void swipeToLeft(AndroidDriver driver) {
            int width = driver.manage().window().getSize().width;
            int height = driver.manage().window().getSize().height;
            TouchAction action3=new TouchAction(driver).press(PointOption.point(width*3/4, height/2)).waitAction(WaitOptions.waitOptions(duration))
                                .moveTo(PointOption.point(width/4,height/2)).release();
           action3.perform();
        }
    
    
        public void swipeToRight(AndroidDriver driver) {
            int width = driver.manage().window().getSize().width;
            int height = driver.manage().window().getSize().height;
            TouchAction action4=new TouchAction(driver).press(PointOption.point(width / 4, height / 2)).waitAction(WaitOptions.waitOptions(duration))
                                    .moveTo(PointOption.point(width*3/4,height/2)).release();
            action4.perform();
        }
    
    }
  • 相关阅读:
    听说你技术很牛?对不起,屁用没有
    Java内存区域与内存溢出异常
    java mongodb连接配置实践——生产环境最优
    MngoDb MongoClientOptions 配置信息及常用配置信息
    java mongodb的MongoOptions生产级配置
    【深入 MongoDB 开发】使用正确的姿势连接分片集群
    MongoDB索引管理-索引的创建、查看、删除
    面试题:判断字符串是否回文
    面试题:Add Two Numbers(模拟单链表)
    面试题:获取一个整数的16进制表现形式
  • 原文地址:https://www.cnblogs.com/tianyumuhe/p/9123350.html
Copyright © 2011-2022 走看看