Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 在获取元素页面中快捷测试元素定位是否可以定位并点击 #476

Merged
merged 4 commits into from
Sep 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading