From 7e9bc2d61259b6d817df31be35042db26802511a Mon Sep 17 00:00:00 2001 From: Eason <291028775@qq.com> Date: Fri, 26 May 2023 00:34:01 +0800 Subject: [PATCH] feat: set snapshot --- .../tests/handlers/AndroidStepHandler.java | 3 ++- .../agent/tests/handlers/IOSStepHandler.java | 19 +++++++++++++++---- .../sonic/agent/websockets/IOSWSServer.java | 5 ++++- 3 files changed, 21 insertions(+), 6 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 ea4a439f..f9e40939 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 @@ -2238,7 +2238,8 @@ public void getElementTextAndAssertWithOperation(HandleContext handleContext, St case "notEqual" -> assertNotEquals(realValue, expect); case "contain" -> assertTrue(realValue.contains(expect)); case "notContain" -> assertFalse(realValue.contains(expect)); - default -> throw new SonicRespException("未支持的文本断言操作类型" + operation + ",无法进行文本断言"); + default -> + throw new SonicRespException("未支持的文本断言操作类型" + operation + ",无法进行文本断言"); } } catch (AssertionError e) { handleContext.setE(e); diff --git a/src/main/java/org/cloud/sonic/agent/tests/handlers/IOSStepHandler.java b/src/main/java/org/cloud/sonic/agent/tests/handlers/IOSStepHandler.java index 73749afe..8340dd68 100755 --- a/src/main/java/org/cloud/sonic/agent/tests/handlers/IOSStepHandler.java +++ b/src/main/java/org/cloud/sonic/agent/tests/handlers/IOSStepHandler.java @@ -131,9 +131,18 @@ public void startIOSDriver(String udId, int wdaPort) throws Exception { } iosDriver.getWdaClient().setGlobalTimeOut(5 * 60 * 1000); log.sendStepLog(StepType.PASS, "连接 WebDriverAgent 成功", ""); - JSONObject appiumSettings = new JSONObject(); - appiumSettings.put("snapshotMaxDepth", 30); - appiumSettings(appiumSettings); + } + + public void setSnapshotMaxDepth(HandleContext handleContext, int depth) { + handleContext.setStepDes("设置控件获取最大遍历深度"); + handleContext.setDetail("设置为 " + depth + " 层"); + try { + JSONObject settings = new JSONObject(); + settings.put("snapshotMaxDepth", depth); + appiumSettings(settings); + } catch (Exception e) { + handleContext.setE(e); + } } public void closeIOSDriver() { @@ -1518,7 +1527,8 @@ public void getElementTextAndAssertWithOperation(HandleContext handleContext, St case "notEqual" -> assertNotEquals(realValue, expect); case "contain" -> assertTrue(realValue.contains(expect)); case "notContain" -> assertFalse(realValue.contains(expect)); - default -> throw new SonicRespException("未支持的文本断言操作类型" + operation + ",无法进行文本断言"); + default -> + throw new SonicRespException("未支持的文本断言操作类型" + operation + ",无法进行文本断言"); } } catch (AssertionError e) { handleContext.setE(e); @@ -1643,6 +1653,7 @@ public void runStep(JSONObject stepJSON, HandleContext handleContext) throws Thr case "freezeSource" -> freezeSource(handleContext); case "thawSource" -> thawSource(handleContext); case "closePocoDriver" -> closePocoDriver(handleContext); + case "setSnapshotMaxDepth" -> setSnapshotMaxDepth(handleContext, step.getInteger("content")); case "iteratorPocoElement" -> iteratorPocoElement(handleContext, eleList.getJSONObject(0).getString("eleName"), eleList.getJSONObject(0).getString("eleType") , eleList.getJSONObject(0).getString("eleValue")); diff --git a/src/main/java/org/cloud/sonic/agent/websockets/IOSWSServer.java b/src/main/java/org/cloud/sonic/agent/websockets/IOSWSServer.java index d01da032..5b8da98d 100755 --- a/src/main/java/org/cloud/sonic/agent/websockets/IOSWSServer.java +++ b/src/main/java/org/cloud/sonic/agent/websockets/IOSWSServer.java @@ -389,11 +389,14 @@ public void onMessage(String message, Session session) { try { JSONObject result = new JSONObject(); result.put("msg", "tree"); - result.put("detail", iosStepHandler.getResource()); HandleContext handleContext = new HandleContext(); if (msg.getBoolean("needImg")) { result.put("img", iosStepHandler.stepScreen(handleContext)); } + if (msg.getInteger("depth") != null) { + iosStepHandler.setSnapshotMaxDepth(handleContext, msg.getInteger("depth")); + } + result.put("detail", iosStepHandler.getResource()); if (handleContext.getE() != null) { log.error(handleContext.getE().getMessage()); JSONObject resultFail = new JSONObject();