Skip to content

Commit

Permalink
Merge pull request #368 from caofengbin/feature/get_ele_attr
Browse files Browse the repository at this point in the history
feat:增加获取控件属性到自定义变量的能力
  • Loading branch information
ZhouYixun authored Jul 1, 2023
2 parents 0620013 + afc08b8 commit a8407b7
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -992,6 +992,19 @@ public void getElementAttr(HandleContext handleContext, String des, String selec
}
}

public void obtainElementAttr(HandleContext handleContext, String des, String selector, String pathValue,
String attr, String variable) {
handleContext.setStepDes("获取控件 " + des + " 属性到变量");
handleContext.setDetail("目标属性:" + attr + ",目标变量:" + variable);
try {
String attrValue = findEle(selector, pathValue).getAttribute(attr);
log.sendStepLog(StepType.INFO, "", attr + " 属性获取结果: " + attrValue);
globalParams.put(variable, attrValue);
} catch (Exception e) {
handleContext.setE(e);
}
}

public void logElementAttr(HandleContext handleContext, String des, String selector, String pathValue, String attr) {
handleContext.setStepDes("日志输出控件 " + des + " 属性");
handleContext.setDetail("目标属性:" + attr);
Expand Down Expand Up @@ -1725,9 +1738,32 @@ public void pocoSwipe(HandleContext handleContext, String des, String selector,
public void getPocoElementAttr(HandleContext handleContext, String des, String selector, String pathValue, String attr, String expect) {
handleContext.setStepDes("验证控件 " + des + " 属性");
handleContext.setDetail("属性:" + attr + ",期望值:" + expect);
String attrValue = getPocoAttrValue(handleContext, selector, pathValue, attr);
log.sendStepLog(StepType.INFO, "", attr + " 属性获取结果: " + attrValue);
try {
assertEquals(attrValue, expect);
} catch (AssertionError e) {
handleContext.setE(e);
}
}

public void obtainPocoElementAttr(HandleContext handleContext, String des, String selector, String pathValue,
String attr, String variable) {
handleContext.setStepDes("获取控件 " + des + " 属性到变量");
handleContext.setDetail("目标属性:" + attr + ",目标变量:" + variable);
try {
String attrValue = getPocoAttrValue(handleContext, selector, pathValue, attr);
log.sendStepLog(StepType.INFO, "", attr + " 属性获取结果: " + attrValue);
globalParams.put(variable, attrValue);
} catch (Exception e) {
handleContext.setE(e);
}
}

private String getPocoAttrValue(HandleContext handleContext, String selector, String pathValue, String attr) {
String attrValue = "";
try {
PocoElement pocoElement = findPocoEle(selector, pathValue);
String attrValue = "";
switch (attr) {
case "type" -> attrValue = pocoElement.getPayload().getType();
case "layer" -> attrValue = pocoElement.getPayload().getLayer();
Expand All @@ -1747,15 +1783,10 @@ public void getPocoElementAttr(HandleContext handleContext, String des, String s
case "size" -> attrValue = pocoElement.getPayload().getSize().toString();
case "pos" -> attrValue = pocoElement.getPayload().getPos().toString();
}
log.sendStepLog(StepType.INFO, "", attr + " 属性获取结果: " + attrValue);
try {
assertEquals(attrValue, expect);
} catch (AssertionError e) {
handleContext.setE(e);
}
} catch (Throwable e) {
handleContext.setE(e);
}
return attrValue;
}

public String getPocoText(HandleContext handleContext, String des, String selector, String pathValue) {
Expand Down Expand Up @@ -2373,6 +2404,10 @@ public void runStep(JSONObject stepJSON, HandleContext handleContext) throws Thr
case "getElementAttr" ->
getElementAttr(handleContext, eleList.getJSONObject(0).getString("eleName"), eleList.getJSONObject(0).getString("eleType")
, eleList.getJSONObject(0).getString("eleValue"), step.getString("text"), step.getString("content"));
case "obtainElementAttr" ->
obtainElementAttr(handleContext, eleList.getJSONObject(0).getString("eleName"),
eleList.getJSONObject(0).getString("eleType"), eleList.getJSONObject(0).getString("eleValue"),
step.getString("text"), step.getString("content"));
case "logElementAttr" ->
logElementAttr(handleContext, eleList.getJSONObject(0).getString("eleName"), eleList.getJSONObject(0).getString("eleType")
, eleList.getJSONObject(0).getString("eleValue"), step.getString("text"));
Expand Down Expand Up @@ -2491,9 +2526,6 @@ public void runStep(JSONObject stepJSON, HandleContext handleContext) throws Thr
case "pocoClick" ->
pocoClick(handleContext, eleList.getJSONObject(0).getString("eleName"), eleList.getJSONObject(0).getString("eleType")
, eleList.getJSONObject(0).getString("eleValue"));
case "logPocoElementAttr" ->
logPocoElementAttr(handleContext, eleList.getJSONObject(0).getString("eleName"), eleList.getJSONObject(0).getString("eleType")
, eleList.getJSONObject(0).getString("eleValue"), step.getString("text"));
case "pocoLongPress" ->
pocoLongPress(handleContext, eleList.getJSONObject(0).getString("eleName"), eleList.getJSONObject(0).getString("eleType")
, eleList.getJSONObject(0).getString("eleValue")
Expand All @@ -2506,6 +2538,13 @@ public void runStep(JSONObject stepJSON, HandleContext handleContext) throws Thr
case "getPocoElementAttr" ->
getPocoElementAttr(handleContext, eleList.getJSONObject(0).getString("eleName"), eleList.getJSONObject(0).getString("eleType")
, eleList.getJSONObject(0).getString("eleValue"), step.getString("text"), step.getString("content"));
case "obtainPocoElementAttr" ->
obtainPocoElementAttr(handleContext, eleList.getJSONObject(0).getString("eleName"),
eleList.getJSONObject(0).getString("eleType"), eleList.getJSONObject(0).getString("eleValue"),
step.getString("text"), step.getString("content"));
case "logPocoElementAttr" ->
logPocoElementAttr(handleContext, eleList.getJSONObject(0).getString("eleName"), eleList.getJSONObject(0).getString("eleType")
, eleList.getJSONObject(0).getString("eleValue"), step.getString("text"));
case "getPocoTextValue" ->
globalParams.put(step.getString("content"), getPocoText(handleContext, eleList.getJSONObject(0).getString("eleName")
, eleList.getJSONObject(0).getString("eleType"), eleList.getJSONObject(0).getString("eleValue")));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -794,6 +794,19 @@ public void getElementAttr(HandleContext handleContext, String des, String selec
}
}

public void obtainElementAttr(HandleContext handleContext, String des, String selector, String pathValue,
String attr, String variable) {
handleContext.setStepDes("获取控件 " + des + " 属性到变量");
handleContext.setDetail("目标属性:" + attr + ",目标变量:" + variable);
try {
String attrValue = findEle(selector, pathValue).getAttribute(attr);
log.sendStepLog(StepType.INFO, "", attr + " 属性获取结果: " + attrValue);
globalParams.put(variable, attrValue);
} catch (Exception e) {
handleContext.setE(e);
}
}

public void logElementAttr(HandleContext handleContext, String des, String selector, String pathValue, String attr) {
handleContext.setStepDes("日志输出控件 " + des + " 属性");
handleContext.setDetail("目标属性:" + attr);
Expand Down Expand Up @@ -1260,9 +1273,32 @@ public void isExistPocoEle(HandleContext handleContext, String des, String selec
public void getPocoElementAttr(HandleContext handleContext, String des, String selector, String pathValue, String attr, String expect) {
handleContext.setStepDes("验证控件 " + des + " 属性");
handleContext.setDetail("属性:" + attr + ",期望值:" + expect);
String attrValue = getPocoAttrValue(handleContext, selector, pathValue, attr);
log.sendStepLog(StepType.INFO, "", attr + " 属性获取结果: " + attrValue);
try {
assertEquals(attrValue, expect);
} catch (AssertionError e) {
handleContext.setE(e);
}
}

public void obtainPocoElementAttr(HandleContext handleContext, String des, String selector, String pathValue,
String attr, String variable) {
handleContext.setStepDes("获取控件 " + des + " 属性到变量");
handleContext.setDetail("目标属性:" + attr + ",目标变量:" + variable);
try {
String attrValue = getPocoAttrValue(handleContext, selector, pathValue, attr);
log.sendStepLog(StepType.INFO, "", attr + " 属性获取结果: " + attrValue);
globalParams.put(variable, attrValue);
} catch (Exception e) {
handleContext.setE(e);
}
}

private String getPocoAttrValue(HandleContext handleContext, String selector, String pathValue, String attr) {
String attrValue = "";
try {
PocoElement pocoElement = findPocoEle(selector, pathValue);
String attrValue = "";
switch (attr) {
case "type" -> attrValue = pocoElement.getPayload().getType();
case "layer" -> attrValue = pocoElement.getPayload().getLayer();
Expand All @@ -1282,15 +1318,10 @@ public void getPocoElementAttr(HandleContext handleContext, String des, String s
case "size" -> attrValue = pocoElement.getPayload().getSize().toString();
case "pos" -> attrValue = pocoElement.getPayload().getPos().toString();
}
log.sendStepLog(StepType.INFO, "", attr + " 属性获取结果: " + attrValue);
try {
assertEquals(attrValue, expect);
} catch (AssertionError e) {
handleContext.setE(e);
}
} catch (Throwable e) {
handleContext.setE(e);
}
return attrValue;
}

public String getPocoText(HandleContext handleContext, String des, String selector, String pathValue) {
Expand Down Expand Up @@ -1769,6 +1800,10 @@ public void runStep(JSONObject stepJSON, HandleContext handleContext) throws Thr
case "getElementAttr" ->
getElementAttr(handleContext, eleList.getJSONObject(0).getString("eleName"), eleList.getJSONObject(0).getString("eleType")
, eleList.getJSONObject(0).getString("eleValue"), step.getString("text"), step.getString("content"));
case "obtainElementAttr" ->
obtainElementAttr(handleContext, eleList.getJSONObject(0).getString("eleName"),
eleList.getJSONObject(0).getString("eleType"), eleList.getJSONObject(0).getString("eleValue"),
step.getString("text"), step.getString("content"));
case "logElementAttr" ->
logElementAttr(handleContext, eleList.getJSONObject(0).getString("eleName"), eleList.getJSONObject(0).getString("eleType")
, eleList.getJSONObject(0).getString("eleValue"), step.getString("text"));
Expand Down Expand Up @@ -1854,9 +1889,6 @@ public void runStep(JSONObject stepJSON, HandleContext handleContext) throws Thr
case "pocoClick" ->
pocoClick(handleContext, eleList.getJSONObject(0).getString("eleName"), eleList.getJSONObject(0).getString("eleType")
, eleList.getJSONObject(0).getString("eleValue"));
case "logPocoElementAttr" ->
logPocoElementAttr(handleContext, eleList.getJSONObject(0).getString("eleName"), eleList.getJSONObject(0).getString("eleType")
, eleList.getJSONObject(0).getString("eleValue"), step.getString("text"));
case "pocoLongPress" ->
pocoLongPress(handleContext, eleList.getJSONObject(0).getString("eleName"), eleList.getJSONObject(0).getString("eleType")
, eleList.getJSONObject(0).getString("eleValue")
Expand All @@ -1869,6 +1901,13 @@ public void runStep(JSONObject stepJSON, HandleContext handleContext) throws Thr
case "getPocoElementAttr" ->
getPocoElementAttr(handleContext, eleList.getJSONObject(0).getString("eleName"), eleList.getJSONObject(0).getString("eleType")
, eleList.getJSONObject(0).getString("eleValue"), step.getString("text"), step.getString("content"));
case "obtainPocoElementAttr" ->
obtainPocoElementAttr(handleContext, eleList.getJSONObject(0).getString("eleName"),
eleList.getJSONObject(0).getString("eleType"), eleList.getJSONObject(0).getString("eleValue"),
step.getString("text"), step.getString("content"));
case "logPocoElementAttr" ->
logPocoElementAttr(handleContext, eleList.getJSONObject(0).getString("eleName"), eleList.getJSONObject(0).getString("eleType")
, eleList.getJSONObject(0).getString("eleValue"), step.getString("text"));
case "getPocoTextValue" ->
globalParams.put(step.getString("content"), getPocoText(handleContext, eleList.getJSONObject(0).getString("eleName")
, eleList.getJSONObject(0).getString("eleType"), eleList.getJSONObject(0).getString("eleValue")));
Expand Down

0 comments on commit a8407b7

Please sign in to comment.