滑动解锁
parent
d90ed03f12
commit
8b0939baf8
|
@ -93,4 +93,24 @@ public interface UpperParamKey {
|
|||
* 滑动解说的坐标点
|
||||
*/
|
||||
String SWIPE_POINT = "swipe_point";
|
||||
|
||||
/**
|
||||
* 滑动解锁左上角点
|
||||
*/
|
||||
String FIRST_POINT = "first_point";
|
||||
|
||||
/**
|
||||
* 滑动解锁左上角右边第一个点
|
||||
*/
|
||||
String SECOND_POINT = "second_point";
|
||||
|
||||
/**
|
||||
* 滑动解锁左上角下边第一个点
|
||||
*/
|
||||
String THIRD_POINT = "third_point";
|
||||
|
||||
/**
|
||||
* 滑动解锁每一行每一列的点数
|
||||
*/
|
||||
String POINT_NUM = "point_num";
|
||||
}
|
||||
|
|
|
@ -1628,76 +1628,89 @@ public class IosAutomationHandler extends AbstractAutomationHandler {
|
|||
response = CmdAutomationResponse.builderFailure(request, "设备与上位机连接断开");
|
||||
return;
|
||||
}
|
||||
String nodeTree = (String) data.get(UpperParamKey.NODE_TREE);
|
||||
String[] pointXpath = new String[3];
|
||||
JSONObject xpathObject = JSON.parseObject((String) data.get(UpperParamKey.FIRST_POINT), JSONObject.class);
|
||||
pointXpath[0] = xpathObject.getString("selector");
|
||||
xpathObject = JSON.parseObject((String) data.get(UpperParamKey.SECOND_POINT), JSONObject.class);
|
||||
pointXpath[1] = xpathObject.getString("selector");
|
||||
xpathObject = JSON.parseObject((String) data.get(UpperParamKey.THIRD_POINT), JSONObject.class);
|
||||
pointXpath[2] = xpathObject.getString("selector");
|
||||
Integer num = (Integer) data.get(UpperParamKey.POINT_NUM);
|
||||
List<Integer> passPoint = (List<Integer>) data.get(UpperParamKey.SWIPE_POINT);
|
||||
Integer waitTimeOut = (Integer) data.get(UpperParamKey.WAIT_TIMEOUT);
|
||||
logger.debug("拿到的nodeTree:{}", nodeTree);
|
||||
Integer waitTimeOut = (Integer) data.get(UpperParamKey.WAIT_TIME_OUT);
|
||||
logger.debug("拿到的左上角的点:{}", pointXpath[0]);
|
||||
logger.debug("拿到的左上角的右边点:{}", pointXpath[1]);
|
||||
logger.debug("拿到的左上角的下边点:{}", pointXpath[2]);
|
||||
logger.debug("拿到的每行每列的点数:{}", num);
|
||||
logger.debug("拿到的经过的点:{}", JSON.toJSONString(passPoint));
|
||||
SearchUiNodeData searchUiNodeData = new SearchUiNodeData();
|
||||
searchUiNodeData.setChain(nodeTree);
|
||||
long startTime = System.currentTimeMillis();
|
||||
long endTime = startTime;
|
||||
logger.debug("步骤:{}开始查找控件,超时时间:{}", request.getStepToken(), waitTimeOut);
|
||||
boolean alreadyFind = false;
|
||||
Map<String, Integer>[] point = new Map[3];
|
||||
UiNodeData uiNodeData = null;
|
||||
int index = 0;
|
||||
int findIndex = 1;
|
||||
do {
|
||||
logger.debug("步骤:{},第{}次开始查找元素", request.getStepToken(), findIndex);
|
||||
searchUiNodeData.setChain(pointXpath[index]);
|
||||
logger.debug("步骤:{},第{}次开始查找第{}个元素", request.getStepToken(), findIndex,index+1);
|
||||
uiNodeData = nkAgent.uiNodeInfo(searchUiNodeData);
|
||||
endTime = System.currentTimeMillis();
|
||||
logger.debug("步骤:{},第{}次查找元素的总时间(累加):{}ms,结果:{}", request.getStepToken(), findIndex, endTime - startTime, JSON.toJSONString(uiNodeData));
|
||||
logger.debug("步骤:{},查找元素的总时间(累加):{}ms,结果:{}", request.getStepToken(), endTime - startTime, JSON.toJSONString(uiNodeData));
|
||||
findIndex++;
|
||||
if (null != uiNodeData && uiNodeData.getX() > 0 && uiNodeData.getY() > 0) {
|
||||
alreadyFind = true;
|
||||
break;
|
||||
}
|
||||
} while ((endTime - startTime) < waitTimeOut * 1000 && !alreadyFind);
|
||||
if (null == uiNodeData) {
|
||||
response = CmdAutomationResponse.builderSuccess(request, "未找到滑动的区域").withData(false);
|
||||
} else {
|
||||
if (uiNodeData.getX() <= 0 && uiNodeData.getY() <= 0) {
|
||||
response = CmdAutomationResponse.builderSuccess(request, "未找到滑动的区域").withData(false);
|
||||
} else {
|
||||
if (null != uiNodeData && (uiNodeData.getX() > 0 || uiNodeData.getY() > 0)) {
|
||||
logger.debug("步骤:{},第{}次开始查找第{}个元素已经找到", request.getStepToken(), findIndex,index+1);
|
||||
int x = uiNodeData.getX();
|
||||
int y = uiNodeData.getY();
|
||||
int width = uiNodeData.getWidth();
|
||||
int height = uiNodeData.getHeight();
|
||||
List<Map<String, Integer>> pointList = new ArrayList<>();
|
||||
logger.info("手势区域,位置=>x:{},y:{},宽:{},高:{}",x,y,width,height);
|
||||
int perWidth = width /3;
|
||||
int perHeight = height /3;
|
||||
int pointY = y - perHeight/2;
|
||||
int n = 1;
|
||||
for (int i = 0; i < 3; i++) {
|
||||
pointY = pointY + perHeight; //每一行的y坐标
|
||||
int pointX = x - perWidth/2;
|
||||
for (int j = 0; j < 3; j++) {
|
||||
pointX = pointX + perWidth;
|
||||
logger.info("第{}个点的坐标x:{},y:{}",n,pointX,pointY);
|
||||
Map<String, Integer> point = new HashMap<>();
|
||||
point.put("x", pointX);
|
||||
point.put("y", pointY);
|
||||
pointList.add(n-1,point);
|
||||
n++;
|
||||
}
|
||||
}
|
||||
logger.info("token:{},滑动解锁的所有坐标集合:{}",request.getStepToken(),JSON.toJSONString(pointList));
|
||||
List<Integer> passPointNum = new ArrayList<>();
|
||||
if (!CollectionUtils.isEmpty(passPoint)) {
|
||||
for (int i=0;i<passPoint.size();i++) {
|
||||
Integer index = passPoint.get(i);
|
||||
Map<String, Integer> point = pointList.get(index - 1);
|
||||
passPointNum.add(point.get("x"));
|
||||
passPointNum.add(point.get("y"));
|
||||
}
|
||||
logger.info("token:{},滑动解锁通过的坐标点:{}",request.getStepToken(),JSON.toJSONString(passPointNum));
|
||||
success = nkAgent.drawLine(JSON.toJSONString(passPointNum));
|
||||
} else {
|
||||
logger.warn("token:{},没有滑动通过的坐标",request.getStepToken());
|
||||
}
|
||||
logger.info("token:{},滑动解锁的结果:{}",request.getStepToken(),success);
|
||||
Map<String, Integer> perPoint = new HashMap<>();
|
||||
perPoint.put("x", x + width / 2);
|
||||
perPoint.put("y", y + height / 2);
|
||||
point[index] = perPoint;
|
||||
index++;
|
||||
findIndex = 1;
|
||||
}
|
||||
} while ((endTime - startTime) < waitTimeOut * 1000 && index < 3);
|
||||
for (int i = 0; i < 3; i++) {
|
||||
if (point[i] == null) {
|
||||
response = CmdAutomationResponse.builderSuccess(request, "定位解锁区域的点不全").withData(false);
|
||||
return;
|
||||
}
|
||||
}
|
||||
//计算每个点的坐标
|
||||
int perWidth = point[1].get("x") - point[0].get("x");
|
||||
int perHeight = point[2].get("y") - point[0].get("y");
|
||||
List<Map<String, Integer>> pointList = new ArrayList<>();
|
||||
int n = 1;
|
||||
for (int i = 0; i < num; i++) {
|
||||
int pointY = point[0].get("y") + i*perHeight; //每一行的y坐标
|
||||
for (int j = 0; j < num; j++) {
|
||||
int pointX = point[0].get("x") + j*perWidth;
|
||||
logger.info("第{}个点的坐标x:{},y:{}",n,pointX,pointY);
|
||||
Map<String, Integer> perPoint = new HashMap<>();
|
||||
perPoint.put("x", pointX);
|
||||
perPoint.put("y", pointY);
|
||||
pointList.add(n-1,perPoint);
|
||||
n++;
|
||||
}
|
||||
}
|
||||
logger.info("token:{},滑动解锁的所有坐标集合:{}",request.getStepToken(),JSON.toJSONString(pointList));
|
||||
//开始滑动
|
||||
List<Integer> passPointNum = new ArrayList<>();
|
||||
if (!CollectionUtils.isEmpty(passPoint)) {
|
||||
for (int i=0;i<passPoint.size();i++) {
|
||||
Integer passIndex = passPoint.get(i);
|
||||
Map<String, Integer> pointMessage = pointList.get(passIndex - 1);
|
||||
passPointNum.add(pointMessage.get("x"));
|
||||
passPointNum.add(pointMessage.get("y"));
|
||||
}
|
||||
logger.info("token:{},滑动解锁通过的坐标点:{}",request.getStepToken(),JSON.toJSONString(passPointNum));
|
||||
success = nkAgent.drawLine(JSON.toJSONString(passPointNum));
|
||||
} else {
|
||||
logger.warn("token:{},没有滑动通过的坐标",request.getStepToken());
|
||||
}
|
||||
logger.info("token:{},滑动解锁的结果:{}",request.getStepToken(),success);
|
||||
if (success) {
|
||||
response = CmdAutomationResponse.builderSuccess(request, "滑动解锁成功").withData(success);
|
||||
} else {
|
||||
|
@ -1708,7 +1721,6 @@ public class IosAutomationHandler extends AbstractAutomationHandler {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
private String getValueByOcr(UiNodeData uiNodeData) {
|
||||
String value = null;
|
||||
String imgBase64 = getOcrAreaByBodeToBase64(uiNodeData);
|
||||
|
|
|
@ -93,4 +93,24 @@ public interface UpperParamKey {
|
|||
*/
|
||||
String SWIPE_POINT = "swipe_point";
|
||||
|
||||
/**
|
||||
* 滑动解锁左上角点
|
||||
*/
|
||||
String FIRST_POINT = "first_point";
|
||||
|
||||
/**
|
||||
* 滑动解锁左上角右边第一个点
|
||||
*/
|
||||
String SECOND_POINT = "second_point";
|
||||
|
||||
/**
|
||||
* 滑动解锁左上角下边第一个点
|
||||
*/
|
||||
String THIRD_POINT = "third_point";
|
||||
|
||||
/**
|
||||
* 滑动解锁每一行每一列的点数
|
||||
*/
|
||||
String POINT_NUM = "point_num";
|
||||
|
||||
}
|
||||
|
|
|
@ -44,6 +44,24 @@ public class ElementHandleParam {
|
|||
|
||||
private List<Integer> passingPoints; //滑动经过的点
|
||||
|
||||
private String firstPoint;
|
||||
private String secondPoint;
|
||||
private String thirdPoint;
|
||||
private Integer pointNum;
|
||||
|
||||
public ElementHandleParam withPointNum(Integer pointNum) {
|
||||
this.setPointNum(pointNum);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ElementHandleParam withPointData(String firstPoint,String secondPoint,String thirdPoint){
|
||||
this.setFirstPoint(firstPoint);
|
||||
this.setSecondPoint(secondPoint);
|
||||
this.setThirdPoint(thirdPoint);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public ElementHandleParam withPassingPoints(List<Integer> passingPoints) {
|
||||
this.setPassingPoints(passingPoints);
|
||||
return this;
|
||||
|
@ -281,4 +299,36 @@ public class ElementHandleParam {
|
|||
public List<Integer> getPassingPoints() {
|
||||
return passingPoints;
|
||||
}
|
||||
|
||||
public String getFirstPoint() {
|
||||
return firstPoint;
|
||||
}
|
||||
|
||||
public void setFirstPoint(String firstPoint) {
|
||||
this.firstPoint = firstPoint;
|
||||
}
|
||||
|
||||
public String getSecondPoint() {
|
||||
return secondPoint;
|
||||
}
|
||||
|
||||
public void setSecondPoint(String secondPoint) {
|
||||
this.secondPoint = secondPoint;
|
||||
}
|
||||
|
||||
public String getThirdPoint() {
|
||||
return thirdPoint;
|
||||
}
|
||||
|
||||
public void setThirdPoint(String thirdPoint) {
|
||||
this.thirdPoint = thirdPoint;
|
||||
}
|
||||
|
||||
public Integer getPointNum() {
|
||||
return pointNum;
|
||||
}
|
||||
|
||||
public void setPointNum(Integer pointNum) {
|
||||
this.pointNum = pointNum;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -953,7 +953,10 @@ public class IOSNewTools {
|
|||
public Boolean pressAndSwipe(
|
||||
IExecuteContext context,
|
||||
@Argument(name = "__deviceDriver", scope = ParamScope.CONTEXT, comment = "设备连接", type = DataType.OBJECT) DeviceDriver deviceDriver,
|
||||
@Argument(name = "targets", scope = ParamScope.STEP, comment = "控件位置", type = DataType.LIST, defaultDisplay = false) List<IStepTarget> targets,
|
||||
@Argument(name = "firstPoint", scope = ParamScope.ARGS, comment = "左上角点", type = DataType.LIST, defaultDisplay = true,inputType = InputType.element) String firstPointStr,
|
||||
@Argument(name = "secondPoint", scope = ParamScope.ARGS, comment = "左上角右边的点", type = DataType.LIST, defaultDisplay = true,inputType = InputType.element) String secondPointStr,
|
||||
@Argument(name = "thirdPoint", scope = ParamScope.ARGS, comment = "左上角下面的点", type = DataType.LIST, defaultDisplay = true,inputType = InputType.element) String thirdPointStr,
|
||||
@Argument(name = "pointNum", scope = ParamScope.ARGS, comment = "每一行、列的点数", type = DataType.INTEGER, defaultDisplay = false,defaultValue = "3") Integer pointNum,
|
||||
@Argument(name = "passingPoints", scope = ParamScope.ARGS, comment = "经过的点", type = DataType.LIST, defaultDisplay = true) List<Integer> passingPoints,
|
||||
@Argument(name = "waitTime", scope = ParamScope.ARGS, comment = "等待时间(单位s)", type = DataType.INTEGER, defaultValue = "30") Integer waitTime,
|
||||
@Argument(name = "preExecuteWait", scope = ParamScope.ARGS, comment = "执行前等待(单位:s)", type = DataType.INTEGER, required = false, defaultValue = "1.0", defaultDisplay = false) Float preExecuteWait,
|
||||
|
@ -964,8 +967,9 @@ public class IOSNewTools {
|
|||
ElementHandleParam param = ElementHandleParam.builder(deviceDriver)
|
||||
.useContext(context)
|
||||
.waitTimeout(waitTime)
|
||||
.withTargets(targets)
|
||||
.withPassingPoints(passingPoints);
|
||||
.withPassingPoints(passingPoints)
|
||||
.withPointData(firstPointStr, secondPointStr, thirdPointStr)
|
||||
.withPointNum(pointNum);
|
||||
Boolean result = false;
|
||||
try {
|
||||
result = AutomationHandleUtil.pressAndSwipe(param);
|
||||
|
|
|
@ -1084,20 +1084,50 @@ public class AutomationHandleUtil {
|
|||
public static Boolean pressAndSwipe(ElementHandleParam param) throws Exception{
|
||||
boolean success = false;
|
||||
String token = UUID.randomUUID().toString();
|
||||
String targetValue = null;
|
||||
for (IStepTarget target : param.getTargets()) {
|
||||
if (UsingType.SELECTOR.equalsIgnoreCase(target.getUsing())) {
|
||||
targetValue = target.getValue();
|
||||
String firstPointStr = param.getFirstPoint();
|
||||
String firstPoint = null;
|
||||
List<JSONObject> firstPointList = JSONObject.parseArray(firstPointStr, JSONObject.class);
|
||||
for (JSONObject jsonObject : firstPointList) {
|
||||
if (UsingType.SELECTOR.equals(jsonObject.getString("using"))) {
|
||||
firstPoint = jsonObject.getString("value");
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (StringUtils.isBlank(targetValue)) {
|
||||
throw new ExecuteException("无法定位到滑动解锁的区域");
|
||||
logger.debug("第一个点的定位xpath:{}", firstPoint);
|
||||
if (StringUtils.isBlank(firstPoint)) {
|
||||
throw new ExecuteException("左上角的点没有定位条件");
|
||||
}
|
||||
String secondPointStr = param.getSecondPoint();
|
||||
String secondPoint = null;
|
||||
List<JSONObject> secondPointList = JSONObject.parseArray(secondPointStr, JSONObject.class);
|
||||
for (JSONObject jsonObject : secondPointList) {
|
||||
if (UsingType.SELECTOR.equals(jsonObject.getString("using"))) {
|
||||
secondPoint = jsonObject.getString("value");
|
||||
break;
|
||||
}
|
||||
}
|
||||
logger.debug("第二个点的定位xpath:{}", secondPoint);
|
||||
if (StringUtils.isBlank(secondPoint)) {
|
||||
throw new ExecuteException("左上角的右边第一个点没有定位条件");
|
||||
}
|
||||
String thirdPointStr = param.getThirdPoint();
|
||||
String thirdPoint = null;
|
||||
List<JSONObject> thirdPointList = JSONObject.parseArray(thirdPointStr, JSONObject.class);
|
||||
for (JSONObject jsonObject : thirdPointList) {
|
||||
if (UsingType.SELECTOR.equals(jsonObject.getString("using"))) {
|
||||
thirdPoint = jsonObject.getString("value");
|
||||
break;
|
||||
}
|
||||
}
|
||||
logger.debug("第三个点的定位xpath:{}", thirdPoint);
|
||||
if (StringUtils.isBlank(secondPoint)) {
|
||||
throw new ExecuteException("左上角的下边第一个点没有定位条件");
|
||||
}
|
||||
Map<String, Object> paramMap = new HashMap<>();
|
||||
JSONObject object = JSON.parseObject(targetValue, JSONObject.class);
|
||||
String xpath = object.getString(UsingType.Key.SELECTOR_KEY);
|
||||
logger.info("拿到的xpath:{}", xpath);
|
||||
paramMap.put(UpperParamKey.NODE_TREE, xpath);
|
||||
paramMap.put(UpperParamKey.FIRST_POINT, firstPoint);
|
||||
paramMap.put(UpperParamKey.SECOND_POINT, secondPoint);
|
||||
paramMap.put(UpperParamKey.THIRD_POINT, thirdPoint);
|
||||
paramMap.put(UpperParamKey.POINT_NUM, param.getPointNum());
|
||||
paramMap.put(UpperParamKey.SWIPE_POINT, param.getPassingPoints());
|
||||
paramMap.put(UpperParamKey.WAIT_TIMEOUT, param.getWaitTimeout());
|
||||
logger.info("参数:{}", JSON.toJSONString(paramMap));
|
||||
|
|
Loading…
Reference in New Issue