From 92443a5536658fd7539697c04ae827b23cb89d0c Mon Sep 17 00:00:00 2001 From: caofengbin <1050430934@qq.com> Date: Mon, 3 Jul 2023 10:39:22 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=89=E5=8D=93=E7=AB=AF=E6=BB=9A=E5=8A=A8?= =?UTF-8?q?=E5=88=B0=EF=BC=8C=E8=80=97=E6=97=B6=E6=94=B9=E4=B8=BA1000?= =?UTF-8?q?=E6=AF=AB=E7=A7=92=EF=BC=8C=E5=85=B6=E4=BB=96=E7=9A=84=E9=BB=98?= =?UTF-8?q?=E8=AE=A4=E6=83=85=E5=86=B5=E4=B8=8B=E4=BE=9D=E7=84=B6=E8=AE=BE?= =?UTF-8?q?=E7=BD=AE=E4=B8=BA500=E6=AF=AB=E7=A7=92?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../agent/tests/handlers/AndroidStepHandler.java | 4 ++-- .../tests/handlers/AndroidTouchHandler.java | 16 +++++++++------- 2 files changed, 11 insertions(+), 9 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 8b18d42f..41257c65 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 @@ -850,9 +850,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); + AndroidTouchHandler.swipe(iDevice, xOffset, screenHeight / 3, xOffset, screenHeight * 2 / 3, 1000); } else if ("down".equals(direction)) { - AndroidTouchHandler.swipe(iDevice, xOffset, screenHeight * 2 / 3, xOffset, screenHeight / 3); + AndroidTouchHandler.swipe(iDevice, xOffset, screenHeight * 2 / 3, xOffset, screenHeight / 3, 1000); } else { handleContext.setE(new Exception("未知的滚动到方向类型设置")); } 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 cb30347c..c67297c2 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 @@ -25,7 +25,6 @@ import org.cloud.sonic.agent.common.maps.AndroidDeviceManagerMap; import org.cloud.sonic.agent.common.maps.HandlerMap; import org.cloud.sonic.agent.tools.PortTool; -import org.cloud.sonic.driver.android.AndroidDriver; import org.cloud.sonic.driver.common.tool.SonicRespException; import java.io.IOException; @@ -45,7 +44,8 @@ public class AndroidTouchHandler { private static final Map touchMap = new ConcurrentHashMap<>(); private static final Map touchModeMap = new ConcurrentHashMap<>(); private static final Map sizeMap = new ConcurrentHashMap<>(); - private static final int SWIPE_DURATION = 500; + // 默认的滑动操作完成时间,单位为毫秒 + private static final int DEFAULT_SWIPE_DURATION = 500; public enum TouchMode { SONIC_APK, @@ -108,6 +108,10 @@ public static void longPress(IDevice iDevice, int x, int y, int time) throws Son } public static void swipe(IDevice iDevice, int x1, int y1, int x2, int y2) throws SonicRespException { + swipe(iDevice, x1, y1, x2, y2, DEFAULT_SWIPE_DURATION); + } + + public static void swipe(IDevice iDevice, int x1, int y1, int x2, int y2, int swipeDuration) throws SonicRespException { switch (getTouchMode(iDevice)) { case SONIC_APK -> { int[] re1 = transferWithRotation(iDevice, x1, y1); @@ -118,14 +122,12 @@ public static void swipe(IDevice iDevice, int x1, int y1, int x2, int y2) throws } catch (InterruptedException e) { e.printStackTrace(); } - // 默认500毫秒完成滑动操作 - int duration = SWIPE_DURATION; long startTime = System.currentTimeMillis(); while (true) { // 当前时间 long currentTime = System.currentTimeMillis(); // 计算时间进度 - float timeProgress = (currentTime - startTime) / (float) duration; + float timeProgress = (currentTime - startTime) / (float) swipeDuration; if (timeProgress >= 1.0f) { // 已经过渡到结束值,停止过渡 writeToOutputStream(iDevice, String.format("move %d %d\n", re2[0], re2[1])); @@ -154,11 +156,11 @@ public static void swipe(IDevice iDevice, int x1, int y1, int x2, int y2) throws writeToOutputStream(iDevice, "up\n"); } case ADB -> AndroidDeviceBridgeTool.executeCommand(iDevice, String.format("input swipe %d %d %d %d %d", - x1, y1, x2, y2, SWIPE_DURATION)); + x1, y1, x2, y2, swipeDuration)); case APPIUM_UIAUTOMATOR2_SERVER -> { AndroidStepHandler curStepHandler = HandlerMap.getAndroidMap().get(iDevice.getSerialNumber()); if (curStepHandler != null && curStepHandler.getAndroidDriver() != null) { - curStepHandler.getAndroidDriver().swipe(x1, y1, x2, y2, SWIPE_DURATION); + curStepHandler.getAndroidDriver().swipe(x1, y1, x2, y2, swipeDuration); } } default -> throw new IllegalStateException("Unexpected value: " + getTouchMode(iDevice));