From c1710d5d80cb80d8c4f72a9f19725b12e603c6a7 Mon Sep 17 00:00:00 2001 From: junhong Date: Mon, 20 Jun 2022 21:35:37 +0800 Subject: [PATCH] =?UTF-8?q?fix(UI=20=E8=87=AA=E5=8A=A8=E5=8C=96):=20UI=20?= =?UTF-8?q?=E6=B5=8B=E8=AF=95=E4=BA=A7=E7=94=9F=E7=9A=84=E6=88=AA=E5=9B=BE?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=B8=85=E7=90=86=E6=9C=BA=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --bug=1014128 --user=周骏弘 【UI测试】UI测试产生的截图缺少清理机制 https://www.tapd.cn/55049933/s/1187159 --- .../api/dto/ApiScenarioReportBaseInfoDTO.java | 1 + .../api/dto/RequestResultExpandDTO.java | 2 ++ .../api/dto/UiScenarioReportBaseInfoDTO.java | 1 + .../api/dto/automation/ExecuteType.java | 2 +- .../dto/definition/RunDefinitionRequest.java | 2 ++ .../definition/request/ParameterConfig.java | 5 ++++ .../api/service/ApiScenarioReportService.java | 23 +++++++++++++++++++ .../controller/ResourceController.java | 4 ++-- .../job/sechedule/CleanUpReportJob.java | 5 ++++ .../metersphere/service/ResourceService.java | 4 ++-- .../api/automation/scenario/DebugRun.vue | 2 ++ 11 files changed, 46 insertions(+), 5 deletions(-) diff --git a/backend/src/main/java/io/metersphere/api/dto/ApiScenarioReportBaseInfoDTO.java b/backend/src/main/java/io/metersphere/api/dto/ApiScenarioReportBaseInfoDTO.java index 1aa1448608..b88957e69f 100644 --- a/backend/src/main/java/io/metersphere/api/dto/ApiScenarioReportBaseInfoDTO.java +++ b/backend/src/main/java/io/metersphere/api/dto/ApiScenarioReportBaseInfoDTO.java @@ -18,4 +18,5 @@ public class ApiScenarioReportBaseInfoDTO { private long rspTime; private String uiImg; private Boolean isNotStep; + private String reportId; } diff --git a/backend/src/main/java/io/metersphere/api/dto/RequestResultExpandDTO.java b/backend/src/main/java/io/metersphere/api/dto/RequestResultExpandDTO.java index b4b7b23f32..a85825c39e 100644 --- a/backend/src/main/java/io/metersphere/api/dto/RequestResultExpandDTO.java +++ b/backend/src/main/java/io/metersphere/api/dto/RequestResultExpandDTO.java @@ -15,6 +15,7 @@ import java.util.Map; public class RequestResultExpandDTO extends RequestResult { private String status; private String uiImg; + private String reportId; private long time; private Map attachInfoMap; @@ -32,6 +33,7 @@ public class RequestResultExpandDTO extends RequestResult { this.setTime(dto.getRspTime()); this.setEndTime(dto.getRspTime() - dto.getReqStartTime()); this.setUiImg(dto.getUiImg()); + this.setReportId(dto.getReportId()); this.setStatus(requestResult.getStatus()); ResponseResult responseResult = this.getResponseResult(); responseResult.setResponseCode(dto.getRspCode()); diff --git a/backend/src/main/java/io/metersphere/api/dto/UiScenarioReportBaseInfoDTO.java b/backend/src/main/java/io/metersphere/api/dto/UiScenarioReportBaseInfoDTO.java index 762f59c77b..b60c3ee6c5 100644 --- a/backend/src/main/java/io/metersphere/api/dto/UiScenarioReportBaseInfoDTO.java +++ b/backend/src/main/java/io/metersphere/api/dto/UiScenarioReportBaseInfoDTO.java @@ -8,4 +8,5 @@ import lombok.Setter; public class UiScenarioReportBaseInfoDTO extends ApiScenarioReportBaseInfoDTO { private Boolean isNotStep = false; private String uiImg; + private String reportId; } diff --git a/backend/src/main/java/io/metersphere/api/dto/automation/ExecuteType.java b/backend/src/main/java/io/metersphere/api/dto/automation/ExecuteType.java index f72e53dca1..3bf85b3416 100644 --- a/backend/src/main/java/io/metersphere/api/dto/automation/ExecuteType.java +++ b/backend/src/main/java/io/metersphere/api/dto/automation/ExecuteType.java @@ -1,5 +1,5 @@ package io.metersphere.api.dto.automation; public enum ExecuteType { - Saved, Completed, Debug, Marge + Saved, Completed, Debug, Marge, Deleted } diff --git a/backend/src/main/java/io/metersphere/api/dto/definition/RunDefinitionRequest.java b/backend/src/main/java/io/metersphere/api/dto/definition/RunDefinitionRequest.java index 30497c9c95..43de8b3592 100644 --- a/backend/src/main/java/io/metersphere/api/dto/definition/RunDefinitionRequest.java +++ b/backend/src/main/java/io/metersphere/api/dto/definition/RunDefinitionRequest.java @@ -16,6 +16,8 @@ public class RunDefinitionRequest { private String runMode; + private String uiRunMode; + private boolean isDebug; private boolean saved; diff --git a/backend/src/main/java/io/metersphere/api/dto/definition/request/ParameterConfig.java b/backend/src/main/java/io/metersphere/api/dto/definition/request/ParameterConfig.java index 370989c471..b3a1335bc8 100644 --- a/backend/src/main/java/io/metersphere/api/dto/definition/request/ParameterConfig.java +++ b/backend/src/main/java/io/metersphere/api/dto/definition/request/ParameterConfig.java @@ -79,6 +79,11 @@ public class ParameterConfig extends MsParameter { private String scenarioId; + /** + * 报告 ID + */ + private String reportId; + private String reportType; private boolean runLocal; diff --git a/backend/src/main/java/io/metersphere/api/service/ApiScenarioReportService.java b/backend/src/main/java/io/metersphere/api/service/ApiScenarioReportService.java index 0df3c4d628..ce2fea1d0e 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiScenarioReportService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiScenarioReportService.java @@ -31,6 +31,7 @@ import io.metersphere.service.SystemParameterService; import io.metersphere.service.UserService; import io.metersphere.track.dto.PlanReportCaseDTO; import io.metersphere.utils.LoggerUtil; +import io.metersphere.xpack.ui.service.UiScenarioReportStructureService; import org.apache.commons.beanutils.BeanMap; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.MapUtils; @@ -90,6 +91,8 @@ public class ApiScenarioReportService { private UiReportServiceProxy uiReportServiceProxy; @Resource private ExtApiScenarioReportResultMapper extApiScenarioReportResultMapper; + @Resource + private UiScenarioReportStructureService uiScenarioReportStructureService; public void saveResult(ResultDTO dto) { // 报告详情内容 @@ -249,6 +252,11 @@ public class ApiScenarioReportService { if (StringUtils.isNotEmpty(report.getTriggerMode()) && report.getTriggerMode().equals("CASE")) { report.setTriggerMode(TriggerMode.MANUAL.name()); } + // UI 调试类型报告不记录更新状态 + if(report.getExecuteType().equals(ExecuteType.Debug.name()) && + report.getReportType().equals(ReportTypeConstants.UI_INDEPENDENT.name())){ + return report; + } apiScenarioReportMapper.updateByPrimaryKeySelective(report); return report; } @@ -502,6 +510,11 @@ public class ApiScenarioReportService { executeTimes = scenario.getExecuteTimes().intValue(); } scenario.setExecuteTimes(executeTimes + 1); + // 针对 UI 调试类型的不需要更新 + if(report.getExecuteType().equals(ExecuteType.Debug.name()) && + report.getReportType().equals(ReportTypeConstants.UI_INDEPENDENT.name())){ + return report; + } uiScenarioMapper.updateByPrimaryKey(scenario); } @@ -621,6 +634,11 @@ public class ApiScenarioReportService { ApiDefinitionExecResultExample execResultExample = new ApiDefinitionExecResultExample(); execResultExample.createCriteria().andIntegratedReportIdEqualTo(request.getId()); definitionExecResultMapper.deleteByExample(execResultExample); + }else{ + // 为 UI 类型报告,需要删除报告产生的截图 + List ids = new ArrayList<>(); + ids.add(request.getId()); + uiScenarioReportStructureService.cleanUpReport(ids); } // 补充逻辑,如果是集成报告则把零时报告全部删除 @@ -741,6 +759,11 @@ public class ApiScenarioReportService { ids = otherIdList; } + if(!BooleanUtils.isNotTrue(reportRequest.getIsUi())){ + // 为 UI 类型报告,需要删除报告产生的截图 + uiScenarioReportStructureService.cleanUpReport(ids); + } + //处理最后剩余的数据 if (!ids.isEmpty()) { ApiScenarioReportDetailExample detailExample = new ApiScenarioReportDetailExample(); diff --git a/backend/src/main/java/io/metersphere/controller/ResourceController.java b/backend/src/main/java/io/metersphere/controller/ResourceController.java index 748936c68e..07535d1834 100644 --- a/backend/src/main/java/io/metersphere/controller/ResourceController.java +++ b/backend/src/main/java/io/metersphere/controller/ResourceController.java @@ -31,8 +31,8 @@ public class ResourceController { } @GetMapping(value = "/ui/get") - public ResponseEntity getUiFile(@RequestParam ("fileName") String fileName) { - return resourceService.getUiResultImage(fileName); + public ResponseEntity getUiFile(@RequestParam ("fileName") String fileName, @RequestParam ("reportId") String reportId) { + return resourceService.getUiResultImage(fileName, reportId); } /** diff --git a/backend/src/main/java/io/metersphere/job/sechedule/CleanUpReportJob.java b/backend/src/main/java/io/metersphere/job/sechedule/CleanUpReportJob.java index add226c7b8..3a336766e2 100644 --- a/backend/src/main/java/io/metersphere/job/sechedule/CleanUpReportJob.java +++ b/backend/src/main/java/io/metersphere/job/sechedule/CleanUpReportJob.java @@ -7,6 +7,7 @@ import io.metersphere.commons.utils.LogUtil; import io.metersphere.dto.ProjectConfig; import io.metersphere.service.ProjectApplicationService; import io.metersphere.service.ProjectService; +import io.metersphere.xpack.ui.service.UiScenarioReportStructureService; import org.apache.commons.lang3.BooleanUtils; import org.apache.commons.lang3.StringUtils; import org.quartz.JobExecutionContext; @@ -23,6 +24,7 @@ public class CleanUpReportJob extends MsScheduleJob { private final ProjectService projectService; private final ProjectApplicationService projectApplicationService; + private final UiScenarioReportStructureService uiScenarioReportStructureService; private static final String UNIT_DAY = "D"; private static final String UNIT_MONTH = "M"; private static final String UNIT_YEAR = "Y"; @@ -31,6 +33,7 @@ public class CleanUpReportJob extends MsScheduleJob { public CleanUpReportJob() { projectService = CommonBeanFactory.getBean(ProjectService.class); projectApplicationService = CommonBeanFactory.getBean(ProjectApplicationService.class); + uiScenarioReportStructureService = CommonBeanFactory.getBean(UiScenarioReportStructureService.class); localDate = LocalDate.now(); } @@ -52,6 +55,8 @@ public class CleanUpReportJob extends MsScheduleJob { if (BooleanUtils.isTrue(config.getCleanLoadReport())) { this.doCleanUp(projectService::cleanUpLoadReport, config.getCleanLoadReportExpr()); } + // 定时删除 UI 调试模式生成的截图 + uiScenarioReportStructureService.cleanUpReport(null); } catch (Exception e) { LogUtil.error("clean up report error."); LogUtil.error(e.getMessage(), e); diff --git a/backend/src/main/java/io/metersphere/service/ResourceService.java b/backend/src/main/java/io/metersphere/service/ResourceService.java index a8d18452d6..a46bf8d79c 100644 --- a/backend/src/main/java/io/metersphere/service/ResourceService.java +++ b/backend/src/main/java/io/metersphere/service/ResourceService.java @@ -46,11 +46,11 @@ public class ResourceService { return getImage(FileUtils.MD_IMAGE_DIR + "/" + name); } - public ResponseEntity getUiResultImage(String name) { + public ResponseEntity getUiResultImage(String name, String reportId) { if (name.contains("/")) { MSException.throwException(Translator.get("invalid_parameter")); } - return getImage(FileUtils.UI_IMAGE_DIR + "/" + name); + return getImage(FileUtils.UI_IMAGE_DIR + "/" + reportId + "/" + name); } public ResponseEntity getImage(String path) { diff --git a/frontend/src/business/components/api/automation/scenario/DebugRun.vue b/frontend/src/business/components/api/automation/scenario/DebugRun.vue index 8d157e2ebf..a33ce834b1 100644 --- a/frontend/src/business/components/api/automation/scenario/DebugRun.vue +++ b/frontend/src/business/components/api/automation/scenario/DebugRun.vue @@ -14,6 +14,7 @@ export default { environment: Map, executeType: String, runMode: String, + uiRunMode: String, debug: Boolean, reportId: String, runData: Object, @@ -79,6 +80,7 @@ export default { reqObj.variables = this.runData.variables; } reqObj.runLocal = this.runLocal; + reqObj.uiRunMode = this.uiRunMode; this.$emit('runRefresh', {}); let url = '/api/automation/run/debug';