Skip to content

Commit

Permalink
fix: 断言控件属性也需要加上计算中心坐标的逻辑处理
Browse files Browse the repository at this point in the history
  • Loading branch information
YeungHoiChiu committed Jun 6, 2024
1 parent a25c291 commit 6791676
Showing 1 changed file with 18 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1003,8 +1003,14 @@ public void getActivity(HandleContext handleContext, String expect) {
public void getElementAttr(HandleContext handleContext, String des, String selector, String pathValue, String attr, String expect) {
handleContext.setStepDes("验证控件 " + des + " 属性");
handleContext.setDetail("属性:" + attr + ",期望值:" + expect);
String attrValue;
try {
String attrValue = findEle(selector, pathValue).getAttribute(attr);
if (attr.equals("centerCoordinate")) {
String bounds = findEle(selector, pathValue).getAttribute("bounds"); // [x1,y1][x2,y2]
attrValue = getCenterCoordinate(bounds);
} else {
attrValue = findEle(selector, pathValue).getAttribute(attr);
}
log.sendStepLog(StepType.INFO, "", attr + " 属性获取结果: " + attrValue);
try {
assertEquals(attrValue, expect);
Expand All @@ -1020,26 +1026,29 @@ public void obtainElementAttr(HandleContext handleContext, String des, String se
String attr, String variable) {
handleContext.setStepDes("获取控件 " + des + " 属性到变量");
handleContext.setDetail("目标属性:" + attr + ",目标变量:" + variable);
String attrValue;
try {
// 自定义一个获取控件中心坐标的逻辑,方便通过控件获取一个坐标去做滑动、拖拽等操作
if (attr.equals("centerCoordinate")) {
String bounds = findEle(selector, pathValue).getAttribute("bounds"); // [x1,y1][x2,y2]
String[] parts = bounds.split("]\\[");
String[] xy = parts[0].substring(1).split(",");
String[] xy2 = parts[1].substring(0, parts[1].length() - 1).split(",");
String attrValue = (Integer.parseInt(xy2[0]) + Integer.parseInt(xy[0])) / 2 + "," + (Integer.parseInt(xy2[1]) + Integer.parseInt(xy[1])) / 2;
log.sendStepLog(StepType.INFO, "", attr + " 属性获取结果: " + attrValue);
globalParams.put(variable, attrValue);
return;
attrValue = getCenterCoordinate(bounds);
} else {
attrValue = findEle(selector, pathValue).getAttribute(attr);
}
String attrValue = findEle(selector, pathValue).getAttribute(attr);
log.sendStepLog(StepType.INFO, "", attr + " 属性获取结果: " + attrValue);
globalParams.put(variable, attrValue);
} catch (Exception e) {
handleContext.setE(e);
}
}

private String getCenterCoordinate(String bounds) {
String[] parts = bounds.split("]\\[");
String[] xy = parts[0].substring(1).split(",");
String[] xy2 = parts[1].substring(0, parts[1].length() - 1).split(",");
return (Integer.parseInt(xy2[0]) + Integer.parseInt(xy[0])) / 2 + "," + (Integer.parseInt(xy2[1]) + Integer.parseInt(xy[1])) / 2;
}

public void logElementAttr(HandleContext handleContext, String des, String selector, String pathValue, String attr) {
handleContext.setStepDes("日志输出控件 " + des + " 属性");
handleContext.setDetail("目标属性:" + attr);
Expand Down

0 comments on commit 6791676

Please sign in to comment.