截图
代码
/*
* 通用向左滑动的方法,不需要传入起始点坐标和终止点坐标
*/
//向左滑通用逻辑
public static void zuohua(){
//1.实例化TouchAction对象,触摸操作相关的
TouchAction touchAction = new TouchAction(androidDriver);
//2.获取到当前屏幕的宽度、高度
int huoqukuanduX = androidDriver.manage().window().getSize().getWidth();
int huoqugaoduY = androidDriver.manage().window().getSize().getHeight();
//3.得到起始坐标
int kaishiX = huoqukuanduX * 3 / 4;
int kaishiY = huoqugaoduY / 2;
//4.得到终止坐标
int zuizhongzuobiaoX = kaishiX / 4;
int zuizhongzuobiaoY = kaishiY / 2;
//把原始滑动时间转换成Duration
Duration duration = Duration.ofMillis(500);
//再去把Duration类型转换成waitOptions类型的
WaitOptions waitOptions = WaitOptions.waitOptions(duration);
//
touchAction.press(PointOption.point(kaishiX, kaishiY)).waitAction(waitOptions).moveTo(PointOption.point(zuizhongzuobiaoX, zuizhongzuobiaoY)).release();
touchAction.perform();
}
//向右滑通用逻辑
public static void youhua(){
//1.实例化TouchAction对象,触摸操作相关的
TouchAction touchAction = new TouchAction(androidDriver);
//2.获取到当前屏幕的宽度、高度
int huoqukuanduX = androidDriver.manage().window().getSize().getWidth();
int huoqugaoduY = androidDriver.manage().window().getSize().getHeight();
//3.得到起始坐标
int kaishiX = huoqukuanduX / 4;
int kaishiY = huoqugaoduY / 2;
//4.得到终止坐标
int zuizhongzuobiaoX = kaishiX * 3 / 4;
int zuizhongzuobiaoY = kaishiY / 2;
//把原始滑动时间转换成Duration
Duration duration = Duration.ofMillis(500);
//再去把Duration类型转换成waitOptions类型的
WaitOptions waitOptions = WaitOptions.waitOptions(duration);
//
touchAction.press(PointOption.point(kaishiX, kaishiY)).waitAction(waitOptions).moveTo(PointOption.point(zuizhongzuobiaoX, zuizhongzuobiaoY)).release();
touchAction.perform();
}
//向下滑通用逻辑
public static void xiahua(){
//1.实例化TouchAction对象,触摸操作相关的
TouchAction touchAction = new TouchAction(androidDriver);
//2.获取到当前屏幕的宽度、高度
int huoqukuanduX = androidDriver.manage().window().getSize().getWidth();
int huoqugaoduY = androidDriver.manage().window().getSize().getHeight();
//3.得到起始坐标
int kaishiX = huoqukuanduX /2;
int kaishiY = huoqugaoduY / 4;
//4.得到终止坐标
int zuizhongzuobiaoX = kaishiX / 2;
int zuizhongzuobiaoY = kaishiY * 3 / 4;
//把原始滑动时间转换成Duration
Duration duration = Duration.ofMillis(500);
//再去把Duration类型转换成waitOptions类型的
WaitOptions waitOptions = WaitOptions.waitOptions(duration);
//
touchAction.press(PointOption.point(kaishiX, kaishiY)).waitAction(waitOptions).moveTo(PointOption.point(zuizhongzuobiaoX, zuizhongzuobiaoY)).release();
touchAction.perform();
}
//向上滑动通用逻辑
public static void shanghua(){
//1.实例化TouchAction对象,触摸操作相关的
TouchAction touchAction = new TouchAction(androidDriver);
//2.获取到当前屏幕的宽度、高度
int huoqukuanduX = androidDriver.manage().window().getSize().getWidth();
int huoqugaoduY = androidDriver.manage().window().getSize().getHeight();
//3.得到起始坐标
int kaishiX = huoqukuanduX /2;
int kaishiY = huoqugaoduY * 3 / 4;
//4.得到终止坐标
int zuizhongzuobiaoX = kaishiX / 2;
int zuizhongzuobiaoY = kaishiY / 4;
//把原始滑动时间转换成Duration
Duration duration = Duration.ofMillis(500);
//再去把Duration类型转换成waitOptions类型的
WaitOptions waitOptions = WaitOptions.waitOptions(duration);
//
touchAction.press(PointOption.point(kaishiX, kaishiY)).waitAction(waitOptions).moveTo(PointOption.point(zuizhongzuobiaoX, zuizhongzuobiaoY)).release();
touchAction.perform();
}