java-clienk 实现通用滑动逻辑
2021/6/25 12:56:46
本文主要是介绍java-clienk 实现通用滑动逻辑,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
截图
代码
/*
* 通用向左滑动的方法,不需要传入起始点坐标和终止点坐标
*/
//向左滑通用逻辑
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();
}
这篇关于java-clienk 实现通用滑动逻辑的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2025-01-11cursor试用出现:Too many free trial accounts used on this machine 的解决方法
- 2025-01-11百万架构师第十四课:源码分析:Spring 源码分析:深入分析IOC那些鲜为人知的细节|JavaGuide
- 2025-01-11不得不了解的高效AI办公工具API
- 2025-01-102025 蛇年,J 人直播带货内容审核团队必备的办公软件有哪 6 款?
- 2025-01-10高效运营背后的支柱:文档管理优化指南
- 2025-01-10年末压力山大?试试优化你的文档管理
- 2025-01-10跨部门协作中的进度追踪重要性解析
- 2025-01-10总结 JavaScript 中的变体函数调用方式
- 2025-01-10HR团队如何通过数据驱动提升管理效率?6个策略
- 2025-01-10WBS实战指南:如何一步步构建高效项目管理框架?