From 465df6dfe7857f9761cd0f4235f5fcf3123555c1 Mon Sep 17 00:00:00 2001 From: caofengbin <1050430934@qq.com> Date: Sat, 20 May 2023 17:02:09 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=AD=E8=A8=80=E5=85=83=E7=B4=A0=E5=AD=98?= =?UTF-8?q?=E5=9C=A8=E7=9A=84=E4=B8=AA=E6=95=B0=EF=BC=8C=E6=94=AF=E6=8C=81?= =?UTF-8?q?iOS=E5=B9=B3=E5=8F=B0=EF=BC=8Cagent=E7=AB=AF=E9=80=BB=E8=BE=91?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=EF=BC=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../agent/tests/handlers/IOSStepHandler.java | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) 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 d42bd0e7..53982256 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 @@ -86,6 +86,9 @@ public class IOSStepHandler { private int targetPort = 0; private String targetPackage = ""; + private static final int IOS_ELEMENT_TYPE = 1004; + private static final int WEB_ELEMENT_TYPE = 1002; + public String getTargetPackage() { return targetPackage; } @@ -658,6 +661,45 @@ public void isExistEle(HandleContext handleContext, String des, String selector, } } + /** + * 断言元素存在个数的方法 + * + * @param handleContext HandleContext + * @param des 元素名称 + * @param selector 定位方式 + * @param pathValue 定位值 + * @param operation 操作类型 + * @param expectedCount 期望数量 + * @param elementType 元素的类型 + */ + public void isExistEleNum(HandleContext handleContext, String des, String selector, String pathValue, String operation + , int expectedCount, int elementType) { + handleContext.setStepDes("判断控件 " + des + " 存在的个数"); + List elementList = new ArrayList<>(); + switch (elementType) { + case IOS_ELEMENT_TYPE: + try { + elementList = findEleList(selector, pathValue); + } catch (SonicRespException e) { + // 查找元素不存在时会抛异常 + } catch (Exception ignored) { + } + break; + default: + handleContext.setE(new AssertionError("未知的元素类型" + elementType + ",无法断言元素个数")); + break; + } + String runDetail = "期望个数:" + operation + " " + expectedCount + ",实际个数:" + " " + (elementList == null ? 0 : elementList.size()); + handleContext.setDetail(runDetail); + AssertUtil assertUtil = new AssertUtil(); + boolean isSuccess = assertUtil.assertElementNum(operation, expectedCount, elementList); + try { + assertTrue(isSuccess); + } catch (AssertionError e) { + handleContext.setE(e); + } + } + public void getElementAttr(HandleContext handleContext, String des, String selector, String pathValue, String attr, String expect) { handleContext.setStepDes("验证控件 " + des + " 属性"); handleContext.setDetail("属性:" + attr + ",期望值:" + expect); @@ -1463,6 +1505,11 @@ public void runStep(JSONObject stepJSON, HandleContext handleContext) throws Thr case "isExistEle" -> isExistEle(handleContext, eleList.getJSONObject(0).getString("eleName"), eleList.getJSONObject(0).getString("eleType") , eleList.getJSONObject(0).getString("eleValue"), step.getBoolean("content")); + case "isExistEleNum" -> isExistEleNum(handleContext, eleList.getJSONObject(0).getString("eleName"), + eleList.getJSONObject(0).getString("eleType"), + eleList.getJSONObject(0).getString("eleValue"), + step.getString("content"), + step.getInteger("text"), IOS_ELEMENT_TYPE); case "clear" -> clear(handleContext, eleList.getJSONObject(0).getString("eleName"), eleList.getJSONObject(0).getString("eleType") , eleList.getJSONObject(0).getString("eleValue"));