Appium的坑
1、运行到driver的操作时,一直报错,不能执行。
原因: java-client-5.3.0.jar 的版本太高了,换成3.3.0后正常。
2、swipe操作不执行
原因:duration =2 (操作时间)太短 ,改为100,可以看到滑动,但翻页不成功。改为50,滑动成功
/** * 上滑 * * @param driver * @param during * @param num */ public static void swipeToUp(AppiumDriver<WebElement> driver,int during, int num) { int width = driver.manage().window().getSize().width; int height = driver.manage().window().getSize().height; for (int i = 0; i < num; i++) { driver.swipe(width / 2, height * 3 / 4, width / 2, height / 4, during); goSleep(3); } } /** * 下拉 * * @param driver * @param during * @param num */ public static void swipeToDown(AppiumDriver<WebElement> driver,int during, int num) { int width = driver.manage().window().getSize().width; int height = driver.manage().window().getSize().height; System.out.println(width); System.out.println(height); for (int i = 0; i < num; i++) { driver.swipe(width / 2, height / 4, width / 2, height * 3 / 4, during); goSleep(3); } } /** * 向左滑动 * * @param driver * @param during * @param num */ public static void swipeToLeft(AppiumDriver<WebElement> driver,int during, int num) { int width = driver.manage().window().getSize().width; int height = driver.manage().window().getSize().height; for (int i = 0; i < num; i++) { driver.swipe(width * 3 / 4, height / 2, width / 4, height / 2, during); goSleep(3); } } /** * 向右滑动 * * @param driver * @param during * @param num */ public static void swipeToRight(AppiumDriver<WebElement> driver,int during, int num) { int width = driver.manage().window().getSize().width; int height = driver.manage().window().getSize().height; for (int i = 0; i < num; i++) { driver.swipe(width / 4, height / 2, width * 3 / 4, height / 2, during); goSleep(3); } }
3、坐标点击
public static void clickScreen(int x, int y, int duration, AppiumDriver drivers) { JavascriptExecutor js = (JavascriptExecutor) drivers; HashMap tapObject = new HashMap(); tapObject.put("x", x); tapObject.put("y", y); tapObject.put("duration", duration); js.executeScript("mobile: tap", tapObject); }
4、adb devices 找不到夜神模拟器
原因:模拟器的adb版本比较低。解决方法:将sdk中的adb,替换模拟器的nox_adb
5、修改方法名后,执行报错
原因不明。解决方法:返回至修改前的状态。