码迷,mamicode.com
首页 > 移动开发 > 详细

Appium 之上划、下划,左划、右划

时间:2018-06-01 21:12:09      阅读:315      评论:0      收藏:0      [点我收藏+]

标签:pre   action   down   port   public   ntop   app   height   OLE   

听说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();
    }

}

 

Appium 之上划、下划,左划、右划

标签:pre   action   down   port   public   ntop   app   height   OLE   

原文地址:https://www.cnblogs.com/tianyumuhe/p/9123350.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!