Skip to content

Commit

Permalink
Merge pull request #476 from YeungHoiChiu/debug-step
Browse files Browse the repository at this point in the history
feat: 在获取元素页面中快捷测试元素定位是否可以定位并点击
  • Loading branch information
ZhouYixun authored Sep 5, 2024
2 parents 0ff073b + be0fcc6 commit 659ef5c
Showing 1 changed file with 45 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,16 @@
package org.cloud.sonic.controller.transport;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import jakarta.websocket.*;
import jakarta.websocket.server.PathParam;
import jakarta.websocket.server.ServerEndpoint;
import lombok.extern.slf4j.Slf4j;
import org.cloud.sonic.controller.config.WsEndpointConfigure;
import org.cloud.sonic.controller.models.domain.Agents;
import org.cloud.sonic.controller.models.dto.ElementsDTO;
import org.cloud.sonic.controller.models.dto.StepsDTO;
import org.cloud.sonic.controller.models.interfaces.AgentStatus;
import org.cloud.sonic.controller.models.interfaces.ConfType;
import org.cloud.sonic.controller.services.*;
Expand All @@ -33,6 +36,8 @@
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Component
Expand Down Expand Up @@ -147,6 +152,13 @@ public void onMessage(String message, Session session) {
case "errCall":
agentsService.errCall(jsonMsg.getInteger("agentId"), jsonMsg.getString("udId"), jsonMsg.getInteger("tem"), jsonMsg.getInteger("type"));
break;
case "generateStep":
JSONObject step = generateStep(jsonMsg, "runStep");
Session agentSession2 = BytesTool.agentSessionMap.get(jsonMsg.getInteger("agentId"));
if (agentSession2 != null) {
BytesTool.sendText(agentSession2, step.toJSONString());
}
break;
}
}

Expand All @@ -170,6 +182,39 @@ private JSONObject findSteps(JSONObject jsonMsg, String msg) {
return steps;
}

/**
* 增加元素定位时,为了方便验证定位是否有效,此时可能还没有入库,所以先生成一个临时的步骤
*
* @param jsonMsg
* @param msg
* @return
*/
private JSONObject generateStep(JSONObject jsonMsg, String msg) {
StepsDTO stepsDTO = new StepsDTO();
ElementsDTO elementsDTO = new ElementsDTO();
elementsDTO.setEleType(jsonMsg.getString("eleType"))
.setEleValue(jsonMsg.getString("element"))
.setEleName("定位控件测试");
List<ElementsDTO> elements = new ArrayList<>();
elements.add(elementsDTO);
String stepType = jsonMsg.getString("eleType").equals("point") ? "tap" : "click";
stepsDTO.setStepType(stepType)
.setConditionType(0)
.setElements(elements)
.setPlatform(jsonMsg.getInteger("pf"));
JSONArray step = new JSONArray();
step.add(stepsDTO);
JSONObject stepObj = new JSONObject();
stepObj.put("msg", msg);
stepObj.put("pf", jsonMsg.getInteger("pf"));
stepObj.put("steps", step);
stepObj.put("sessionId", jsonMsg.getString("sessionId"));
stepObj.put("pwd", jsonMsg.getString("pwd"));
stepObj.put("udId", jsonMsg.getString("udId"));
return stepObj;
}


@OnClose
public void onClose(Session session) {
log.info("Agent: {} disconnected.", session.getId());
Expand Down

0 comments on commit 659ef5c

Please sign in to comment.