diff --git a/sonic-server-controller/src/main/java/org/cloud/sonic/controller/transport/TransportServer.java b/sonic-server-controller/src/main/java/org/cloud/sonic/controller/transport/TransportServer.java index f322988f..a6e96a63 100644 --- a/sonic-server-controller/src/main/java/org/cloud/sonic/controller/transport/TransportServer.java +++ b/sonic-server-controller/src/main/java/org/cloud/sonic/controller/transport/TransportServer.java @@ -18,6 +18,7 @@ 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; @@ -25,6 +26,8 @@ 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.*; @@ -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 @@ -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; } } @@ -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 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());