From 70226a4c98c3cb0873af71d882e9523cd39ac5d5 Mon Sep 17 00:00:00 2001 From: caofengbin <1050430934@qq.com> Date: Mon, 19 Jun 2023 12:14:12 +0800 Subject: [PATCH] =?UTF-8?q?touchHandler=E4=B8=AD=E7=9A=84tap,longPress?= =?UTF-8?q?=E4=B8=8Eswipe=E6=96=B9=E6=B3=95=E5=8E=BB=E6=8E=89=E9=A2=9D?= =?UTF-8?q?=E5=A4=96=E7=9A=84AndroidDriver=E5=8F=82=E6=95=B0=E4=BC=A0?= =?UTF-8?q?=E9=80=92=E8=BF=87=E7=A8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tests/handlers/AndroidStepHandler.java | 36 +++++++++---------- .../tests/handlers/AndroidTouchHandler.java | 6 ++-- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/src/main/java/org/cloud/sonic/agent/tests/handlers/AndroidStepHandler.java b/src/main/java/org/cloud/sonic/agent/tests/handlers/AndroidStepHandler.java index a2e8a739..c01579f7 100755 --- a/src/main/java/org/cloud/sonic/agent/tests/handlers/AndroidStepHandler.java +++ b/src/main/java/org/cloud/sonic/agent/tests/handlers/AndroidStepHandler.java @@ -656,7 +656,7 @@ public void longPressPoint(HandleContext handleContext, String des, String xy, i handleContext.setStepDes("长按" + des); handleContext.setDetail("长按坐标" + time + "毫秒 (" + point[0] + "," + point[1] + ")"); try { - AndroidTouchHandler.longPress(iDevice, point[0], point[1], time, androidDriver); + AndroidTouchHandler.longPress(iDevice, point[0], point[1], time); } catch (Exception e) { handleContext.setE(e); } @@ -685,7 +685,7 @@ public void tap(HandleContext handleContext, String des, String xy) { handleContext.setStepDes("点击" + des); handleContext.setDetail("点击坐标(" + point[0] + "," + point[1] + ")"); try { - AndroidTouchHandler.tap(iDevice, point[0], point[1], androidDriver); + AndroidTouchHandler.tap(iDevice, point[0], point[1]); } catch (Exception e) { handleContext.setE(e); } @@ -701,7 +701,7 @@ public void swipePoint(HandleContext handleContext, String des1, String xy1, Str handleContext.setStepDes("滑动拖拽" + des1 + "到" + des2); handleContext.setDetail("拖动坐标(" + point1[0] + "," + point1[1] + ")到(" + point2[0] + "," + point2[1] + ")"); try { - AndroidTouchHandler.swipe(iDevice, point1[0], point1[1], point2[0], point2[1], androidDriver); + AndroidTouchHandler.swipe(iDevice, point1[0], point1[1], point2[0], point2[1]); } catch (Exception e) { handleContext.setE(e); } @@ -717,7 +717,7 @@ public void swipe(HandleContext handleContext, String des, String selector, Stri int y2 = webElement2.getRect().getY(); handleContext.setStepDes("滑动拖拽" + des + "到" + des2); handleContext.setDetail("拖动坐标(" + x1 + "," + y1 + ")到(" + x2 + "," + y2 + ")"); - AndroidTouchHandler.swipe(iDevice, x1, y1, x2, y2, androidDriver); + AndroidTouchHandler.swipe(iDevice, x1, y1, x2, y2); } catch (Exception e) { handleContext.setE(e); } @@ -744,7 +744,7 @@ public void swipeByDefinedDirection(HandleContext handleContext, String slideDir log.sendStepLog(StepType.INFO, "", "滑动距离超出设备顶部,默认取顶部边界值" + "<" + targetY + ">"); } try { - AndroidTouchHandler.swipe(iDevice, centerX, centerY, centerX, targetY, androidDriver); + AndroidTouchHandler.swipe(iDevice, centerX, centerY, centerX, targetY); } catch (Exception e) { handleContext.setE(e); } @@ -758,7 +758,7 @@ public void swipeByDefinedDirection(HandleContext handleContext, String slideDir log.sendStepLog(StepType.INFO, "", "滑动距离超出设备底部,默认取底部边界值" + "<" + targetY + ">"); } try { - AndroidTouchHandler.swipe(iDevice, centerX, centerY, centerX, targetY, androidDriver); + AndroidTouchHandler.swipe(iDevice, centerX, centerY, centerX, targetY); } catch (Exception e) { handleContext.setE(e); } @@ -772,7 +772,7 @@ public void swipeByDefinedDirection(HandleContext handleContext, String slideDir log.sendStepLog(StepType.INFO, "", "滑动距离超出设备左侧,默认取左侧边界值" + "<" + targetX + ">"); } try { - AndroidTouchHandler.swipe(iDevice, centerX, centerY, targetX, centerY, androidDriver); + AndroidTouchHandler.swipe(iDevice, centerX, centerY, targetX, centerY); } catch (Exception e) { handleContext.setE(e); } @@ -786,7 +786,7 @@ public void swipeByDefinedDirection(HandleContext handleContext, String slideDir log.sendStepLog(StepType.INFO, "", "滑动距离超出设备右侧,默认取右侧边界值" + "<" + targetX + ">"); } try { - AndroidTouchHandler.swipe(iDevice, centerX, centerY, targetX, centerY, androidDriver); + AndroidTouchHandler.swipe(iDevice, centerX, centerY, targetX, centerY); } catch (Exception e) { handleContext.setE(e); } @@ -809,7 +809,7 @@ public void longPress(HandleContext handleContext, String des, String selector, int height = webElement.getRect().getHeight(); int centerX = x + (int) Math.ceil(width / 2.0); int centerY = y + (int) Math.ceil(height / 2.0); - AndroidTouchHandler.longPress(iDevice, centerX, centerY, time, androidDriver); + AndroidTouchHandler.longPress(iDevice, centerX, centerY, time); } catch (Exception e) { handleContext.setE(e); } @@ -846,9 +846,9 @@ public void scrollToEle(HandleContext handleContext, String des, String selector try { if ("up".equals(direction)) { - AndroidTouchHandler.swipe(iDevice, xOffset, screenHeight / 3, xOffset, screenHeight * 2 / 3, androidDriver); + AndroidTouchHandler.swipe(iDevice, xOffset, screenHeight / 3, xOffset, screenHeight * 2 / 3); } else if ("down".equals(direction)) { - AndroidTouchHandler.swipe(iDevice, xOffset, screenHeight * 2 / 3, xOffset, screenHeight / 3, androidDriver); + AndroidTouchHandler.swipe(iDevice, xOffset, screenHeight * 2 / 3, xOffset, screenHeight / 3); } else { handleContext.setE(new Exception("未知的滚动到方向类型设置")); } @@ -1085,7 +1085,7 @@ public void clickByImg(HandleContext handleContext, String des, String pathValue } if (findResult != null) { try { - AndroidTouchHandler.tap(iDevice, findResult.getX(), findResult.getY(), androidDriver); + AndroidTouchHandler.tap(iDevice, findResult.getX(), findResult.getY()); } catch (Exception e) { log.sendStepLog(StepType.ERROR, "点击" + des + "失败!", ""); handleContext.setE(e); @@ -1349,19 +1349,19 @@ public void runMonkey(HandleContext handleContext, JSONObject content, List= finalSystemEvent && random < (finalSystemEvent + finalTapEvent)) { int x = new Random().nextInt(width - 60) + 60; int y = new Random().nextInt(height - 60) + 60; - AndroidTouchHandler.tap(iDevice, x, y, androidDriver); + AndroidTouchHandler.tap(iDevice, x, y); } if (random >= (finalSystemEvent + finalTapEvent) && random < (finalSystemEvent + finalTapEvent + finalLongPressEvent)) { int x = new Random().nextInt(width - 60) + 60; int y = new Random().nextInt(height - 60) + 60; - AndroidTouchHandler.longPress(iDevice, x, y, (new Random().nextInt(3) + 1) * 1000, androidDriver); + AndroidTouchHandler.longPress(iDevice, x, y, (new Random().nextInt(3) + 1) * 1000); } if (random >= (finalSystemEvent + finalTapEvent + finalLongPressEvent) && random < (finalSystemEvent + finalTapEvent + finalLongPressEvent + finalSwipeEvent)) { int x1 = new Random().nextInt(width - 60) + 60; int y1 = new Random().nextInt(height - 80) + 80; int x2 = new Random().nextInt(width - 60) + 60; int y2 = new Random().nextInt(height - 80) + 80; - AndroidTouchHandler.swipe(iDevice, x1, y1, x2, y2, androidDriver); + AndroidTouchHandler.swipe(iDevice, x1, y1, x2, y2); } if (random >= (finalSystemEvent + finalTapEvent + finalLongPressEvent + finalSwipeEvent) && random < (finalSystemEvent + finalTapEvent + finalLongPressEvent + finalSwipeEvent + finalNavEvent)) { int a = new Random().nextInt(2); @@ -1671,7 +1671,7 @@ public void pocoClick(HandleContext handleContext, String des, String selector, if (w != null) { List pos = w.getPayload().getPos(); int[] realCoordinates = getTheRealCoordinatesOfPoco(pos.get(0), pos.get(1)); - AndroidTouchHandler.tap(iDevice, realCoordinates[0], realCoordinates[1], androidDriver); + AndroidTouchHandler.tap(iDevice, realCoordinates[0], realCoordinates[1]); } else { throw new SonicRespException(value + " not found!"); } @@ -1688,7 +1688,7 @@ public void pocoLongPress(HandleContext handleContext, String des, String select if (w != null) { List pos = w.getPayload().getPos(); int[] realCoordinates = getTheRealCoordinatesOfPoco(pos.get(0), pos.get(1)); - AndroidTouchHandler.longPress(iDevice, realCoordinates[0], realCoordinates[1], time, androidDriver); + AndroidTouchHandler.longPress(iDevice, realCoordinates[0], realCoordinates[1], time); } else { throw new SonicRespException(value + " not found!"); } @@ -1709,7 +1709,7 @@ public void pocoSwipe(HandleContext handleContext, String des, String selector, List pos2 = w2.getPayload().getPos(); int[] realCoordinate2 = getTheRealCoordinatesOfPoco(pos2.get(0), pos2.get(1)); - AndroidTouchHandler.swipe(iDevice, realCoordinates1[0], realCoordinates1[1], realCoordinate2[0], realCoordinate2[1], androidDriver); + AndroidTouchHandler.swipe(iDevice, realCoordinates1[0], realCoordinates1[1], realCoordinate2[0], realCoordinate2[1]); } else { throw new SonicRespException(value + " or " + value2 + " not found!"); } diff --git a/src/main/java/org/cloud/sonic/agent/tests/handlers/AndroidTouchHandler.java b/src/main/java/org/cloud/sonic/agent/tests/handlers/AndroidTouchHandler.java index 4bd93e51..d12cf02b 100755 --- a/src/main/java/org/cloud/sonic/agent/tests/handlers/AndroidTouchHandler.java +++ b/src/main/java/org/cloud/sonic/agent/tests/handlers/AndroidTouchHandler.java @@ -59,7 +59,7 @@ public static TouchMode getTouchMode(IDevice iDevice) { return touchModeMap.get(iDevice.getSerialNumber()) == null ? TouchMode.ADB : touchModeMap.get(iDevice.getSerialNumber()); } - public static void tap(IDevice iDevice, int x, int y, AndroidDriver androidDriver) throws SonicRespException { + public static void tap(IDevice iDevice, int x, int y) throws SonicRespException { switch (getTouchMode(iDevice)) { case SONIC_APK -> { int[] re = transferWithRotation(iDevice, x, y); @@ -82,7 +82,7 @@ public static void tap(IDevice iDevice, int x, int y, AndroidDriver androidDrive } } - public static void longPress(IDevice iDevice, int x, int y, int time, AndroidDriver androidDriver) throws SonicRespException { + public static void longPress(IDevice iDevice, int x, int y, int time) throws SonicRespException { switch (getTouchMode(iDevice)) { case SONIC_APK -> { int[] re = transferWithRotation(iDevice, x, y); @@ -105,7 +105,7 @@ public static void longPress(IDevice iDevice, int x, int y, int time, AndroidDri } } - public static void swipe(IDevice iDevice, int x1, int y1, int x2, int y2, AndroidDriver androidDriver) throws SonicRespException { + public static void swipe(IDevice iDevice, int x1, int y1, int x2, int y2) throws SonicRespException { switch (getTouchMode(iDevice)) { case SONIC_APK -> { int[] re1 = transferWithRotation(iDevice, x1, y1);