Appium 1.7 实现上下、左右滑动页面方法

来源:互联网 发布:网络常见的拓扑形式有 编辑:程序博客网 时间:2024/06/08 11:20
Appium 1.7 实现上下、左右滑动页面方法
说明:之前的文章:Appium 实现上下、左右滑动页面 只适用于Appium 1.6.4及以下
Appium升级到1.7 后的问题:
(1)以前的driver.swipe方法不能用了。
(2)即便使用TouchAction类的滑动方法也不能用了,因为waitAction有变化(waitAction(Duration)注意 这里表是Duration对象,而不是以前直接的数字,如waitAction(1000))。
解决方法:
新建类:SwipeScreen.java
import java.time.Duration;import io.appium.java_client.TouchAction;import io.appium.java_client.android.AndroidDriver;public class SwipeScreen{ static Duration duration=Duration.ofSeconds(1);public static void swipeUp(AndroidDriver driver) {  int width = driver.manage().window().getSize().width;  int height = driver.manage().window().getSize().height; TouchAction action1 = new TouchAction(driver).press(width / 2,height * 4/ 5).waitAction(duration).moveTo(width /2, height /4).release(); action1.perform(); } public static void swipeDown(AndroidDriver driver)// scroll down to refresh {  int width = driver.manage().window().getSize().width;  int height = driver.manage().window().getSize().height; TouchAction action1 = new TouchAction(driver).press(width / 2,height/4).waitAction(duration).moveTo(width /2, height* 3/4).release();        action1.perform(); } public static void swipeLeft(AndroidDriver driver) {  int width = driver.manage().window().getSize().width;  int height = driver.manage().window().getSize().height; TouchAction action1 = new TouchAction(driver).press(width -10,height/2).waitAction(duration).moveTo(width /4, height /2).release();        action1.perform(); } public static void swipeRight(AndroidDriver driver) {  int width = driver.manage().window().getSize().width;  int height = driver.manage().window().getSize().height; TouchAction action1 = new TouchAction(driver).press(10,height/2).waitAction(duration).moveTo(width *3/4+10, height /2).release();        action1.perform(); }}
使用方法:
SwipeScreen.swipeUp(driver);

原创粉丝点击