public TouchAction findBySwipe(String diret) {
//todo: 多平台的滑动
AppiumDriver driver = Driver.getInstance().appiumDriver;
int width = driver.manage().window().getSize().width;//获取当前屏幕的宽度
int height = driver.manage().window().getSize().height;//获取当前屏幕的高度
Duration duration = Duration.ofSeconds(1);
TouchAction action=null;
switch (diret) {
case "Right":
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
e.printStackTrace();
}
action= new TouchAction(driver).press(PointOption.point(width / 4, height / 2)).waitAction(WaitOptions.waitOptions(duration))
.moveTo(PointOption.point(width * 3 / 4, height / 2));
case "Left":
try {
Thread.sleep(3000);
action= new TouchAction(driver).press(PointOption.point(width * 7 / 8, height / 2)).waitAction(WaitOptions.waitOptions(duration))
.moveTo(PointOption.point(width / 8, height / 2));
} catch (InterruptedException e) {
e.printStackTrace();
}
}
return action.release().perform();
}
把滑动,简单封装了下
case 里,连续滑动了 2 次,第一次滑动,页面显示滑动成功了,但代码报了异常,停止了。难道是这个 action 执行完后还有其它操作吗