Skip to content

Commit

Permalink
断言元素存在的个数,支持iOS平台,agent端逻辑修改,
Browse files Browse the repository at this point in the history
  • Loading branch information
caofengbin committed May 20, 2023
1 parent 32b0163 commit 465df6d
Showing 1 changed file with 47 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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"));
Expand Down

0 comments on commit 465df6d

Please sign in to comment.