diff --git a/backend/src/main/java/io/metersphere/api/controller/ApiAutomationController.java b/backend/src/main/java/io/metersphere/api/controller/ApiAutomationController.java index ebf72ab5ba..7fde7c77f1 100644 --- a/backend/src/main/java/io/metersphere/api/controller/ApiAutomationController.java +++ b/backend/src/main/java/io/metersphere/api/controller/ApiAutomationController.java @@ -202,9 +202,8 @@ public class ApiAutomationController { @MsAuditLog(module = "api_automation", type = OperLogConstants.DEBUG, title = "#request.scenarioName", sourceId = "#request.scenarioId", project = "#request.projectId") public void runDebug(@RequestPart("request") RunDefinitionRequest request, @RequestPart(value = "bodyFiles", required = false) List bodyFiles, @RequestPart(value = "scenarioFiles", required = false) List scenarioFiles) { - request.setExecuteType(ExecuteType.Debug.name()); - if (request.isSaved()) { - request.setExecuteType(ExecuteType.Saved.name()); + if (StringUtils.isEmpty(request.getExecuteType())) { + request.setExecuteType(ExecuteType.Debug.name()); } apiAutomationService.debugRun(request, bodyFiles, scenarioFiles); } diff --git a/backend/src/main/java/io/metersphere/api/exec/scenario/ApiScenarioExecuteService.java b/backend/src/main/java/io/metersphere/api/exec/scenario/ApiScenarioExecuteService.java index 1cb6d5e44b..ece60cdc39 100644 --- a/backend/src/main/java/io/metersphere/api/exec/scenario/ApiScenarioExecuteService.java +++ b/backend/src/main/java/io/metersphere/api/exec/scenario/ApiScenarioExecuteService.java @@ -377,21 +377,23 @@ public class ApiScenarioExecuteService { } catch (Exception e) { MSException.throwException(e.getMessage()); } - APIScenarioReportResult report = apiScenarioReportService.init(request.getId(), request.getScenarioId(), request.getScenarioName(), ReportTriggerMode.MANUAL.name(), request.getExecuteType(), request.getProjectId(), - SessionUtils.getUserId(), request.getConfig(), request.getId()); - apiScenarioReportMapper.insert(report); if (request.isSaved()) { - ApiScenarioWithBLOBs scenario = apiScenarioMapper.selectByPrimaryKey(request.getScenarioId()); - apiScenarioReportStructureService.save(scenario, report.getId(), request.getConfig() != null ? request.getConfig().getReportType() : null); - } else { - if (request.getTestElement() != null && CollectionUtils.isNotEmpty(request.getTestElement().getHashTree())) { - ApiScenarioWithBLOBs scenario = new ApiScenarioWithBLOBs(); - scenario.setId(request.getScenarioId()); - MsTestElement testElement = request.getTestElement().getHashTree().get(0).getHashTree().get(0); - if (testElement != null) { - scenario.setName(testElement.getName()); - scenario.setScenarioDefinition(JSON.toJSONString(testElement)); - apiScenarioReportStructureService.save(scenario, report.getId(), request.getConfig() != null ? request.getConfig().getReportType() : null); + APIScenarioReportResult report = apiScenarioReportService.init(request.getId(), request.getScenarioId(), request.getScenarioName(), ReportTriggerMode.MANUAL.name(), request.getExecuteType(), request.getProjectId(), + SessionUtils.getUserId(), request.getConfig(), request.getId()); + apiScenarioReportMapper.insert(report); + ApiScenarioWithBLOBs scenarioWithBLOBs = apiScenarioMapper.selectByPrimaryKey(request.getScenarioId()); + if (scenarioWithBLOBs != null) { + apiScenarioReportStructureService.save(scenarioWithBLOBs, report.getId(), request.getConfig() != null ? request.getConfig().getReportType() : null); + } else { + if (request.getTestElement() != null && CollectionUtils.isNotEmpty(request.getTestElement().getHashTree())) { + ApiScenarioWithBLOBs scenario = new ApiScenarioWithBLOBs(); + scenario.setId(request.getScenarioId()); + MsTestElement testElement = request.getTestElement().getHashTree().get(0).getHashTree().get(0); + if (testElement != null) { + scenario.setName(testElement.getName()); + scenario.setScenarioDefinition(JSON.toJSONString(testElement)); + apiScenarioReportStructureService.save(scenario, report.getId(), request.getConfig() != null ? request.getConfig().getReportType() : null); + } } } } diff --git a/backend/src/main/java/io/metersphere/api/service/ApiScenarioReportStructureService.java b/backend/src/main/java/io/metersphere/api/service/ApiScenarioReportStructureService.java index 982e7bf708..1c8a9d2be9 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiScenarioReportStructureService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiScenarioReportStructureService.java @@ -78,16 +78,8 @@ public class ApiScenarioReportStructureService { JSONObject element = JSON.parseObject(apiScenario.getScenarioDefinition()); StepTreeDTO dto = null; if (element != null && element.getBoolean("enable")) { - String referenced = element.getString("referenced"); + element = getRefElement(element); String type = element.getString("type"); - if (StringUtils.equals(referenced, MsTestElementConstants.REF.name())) { - if (StringUtils.equals(element.getString("type"), "scenario")) { - ApiScenarioWithBLOBs scenarioWithBLOBs = CommonBeanFactory.getBean(ApiScenarioMapper.class).selectByPrimaryKey(element.getString("id")); - if (scenarioWithBLOBs != null) { - element = JSON.parseObject(scenarioWithBLOBs.getScenarioDefinition()); - } - } - } String resourceId = "JSR223Processor".equals(type) ? element.getString("resourceId") : element.getString("id"); if (StringUtils.equals(reportType, RunModeConstants.SET_REPORT.toString())) { if (StringUtils.isNotEmpty(resourceId) && StringUtils.isNotEmpty(apiScenario.getId()) && !resourceId.contains(apiScenario.getId())) { @@ -104,19 +96,24 @@ public class ApiScenarioReportStructureService { return dto; } + private static JSONObject getRefElement(JSONObject element) { + String referenced = element.getString("referenced"); + if (StringUtils.equals(referenced, MsTestElementConstants.REF.name())) { + if (StringUtils.equals(element.getString("type"), "scenario")) { + ApiScenarioWithBLOBs scenarioWithBLOBs = CommonBeanFactory.getBean(ApiScenarioMapper.class).selectByPrimaryKey(element.getString("id")); + if (scenarioWithBLOBs != null) { + return JSON.parseObject(scenarioWithBLOBs.getScenarioDefinition()); + } + } + } + return element; + } + public static void dataFormatting(JSONArray hashTree, StepTreeDTO dto, String id, String reportType) { for (int i = 0; i < hashTree.size(); i++) { JSONObject element = hashTree.getJSONObject(i); if (element != null && element.getBoolean("enable")) { - String referenced = element.getString("referenced"); - if (StringUtils.equals(referenced, MsTestElementConstants.REF.name())) { - if (StringUtils.equals(element.getString("type"), "scenario")) { - ApiScenarioWithBLOBs scenarioWithBLOBs = CommonBeanFactory.getBean(ApiScenarioMapper.class).selectByPrimaryKey(element.getString("id")); - if (scenarioWithBLOBs != null) { - element = JSON.parseObject(scenarioWithBLOBs.getScenarioDefinition()); - } - } - } + element = getRefElement(element); String type = element.getString("type"); String resourceId = "JSR223Processor".equals(type) ? element.getString("resourceId") : element.getString("id"); if (StringUtils.equals(reportType, RunModeConstants.SET_REPORT.toString())) { @@ -217,6 +214,11 @@ public class ApiScenarioReportStructureService { dto.setErrorCode(reportResults.get(0).getErrorCode()); } } + if (StringUtils.isNotEmpty(dto.getType()) && requests.contains(dto.getType()) && dto.getValue() == null) { + RequestResult requestResult = new RequestResult(); + requestResult.setName(dto.getLabel()); + dto.setValue(requestResult); + } if (CollectionUtils.isNotEmpty(dto.getChildren())) { reportFormatting(dto.getChildren(), maps); if (StringUtils.isEmpty(dto.getErrorCode())) { diff --git a/frontend/src/business/components/api/automation/scenario/ApiScenarioList.vue b/frontend/src/business/components/api/automation/scenario/ApiScenarioList.vue index 4e80d4e0ed..d17b7d69c4 100644 --- a/frontend/src/business/components/api/automation/scenario/ApiScenarioList.vue +++ b/frontend/src/business/components/api/automation/scenario/ApiScenarioList.vue @@ -283,7 +283,7 @@ :dialog-title="$t('test_track.case.batch_edit_case')"/> - diff --git a/frontend/src/business/components/api/automation/scenario/DebugRun.vue b/frontend/src/business/components/api/automation/scenario/DebugRun.vue index c4e7756604..10a49c7736 100644 --- a/frontend/src/business/components/api/automation/scenario/DebugRun.vue +++ b/frontend/src/business/components/api/automation/scenario/DebugRun.vue @@ -12,6 +12,7 @@ export default { components: {}, props: { environment: Map, + executeType: String, runMode: String, debug: Boolean, reportId: String, @@ -70,7 +71,7 @@ export default { testPlan.hashTree.push(threadGroup); this.sort(testPlan.hashTree); let reqObj = { - id: this.reportId, reportId: this.reportId, scenarioName: this.runData.name, saved: this.saved, runMode: this.runMode, + id: this.reportId, reportId: this.reportId, scenarioName: this.runData.name, saved: this.saved, runMode: this.runMode, executeType: this.executeType, scenarioId: this.runData.id, testElement: testPlan, projectId: getCurrentProjectID(), environmentMap: strMapToObj(map), environmentType: this.environmentType, environmentGroupId: this.environmentGroupId, environmentJson: JSON.stringify(strMapToObj(map)) }; diff --git a/frontend/src/business/components/api/automation/scenario/EditApiScenario.vue b/frontend/src/business/components/api/automation/scenario/EditApiScenario.vue index cb7d53d7be..e93b47545d 100644 --- a/frontend/src/business/components/api/automation/scenario/EditApiScenario.vue +++ b/frontend/src/business/components/api/automation/scenario/EditApiScenario.vue @@ -268,7 +268,7 @@ - @@ -488,6 +488,7 @@ export default { loading: false }, debug: false, + saved: false, debugLoading: false, reqTotal: 0, reqSuccess: 0, @@ -1201,6 +1202,7 @@ export default { this.clearResult(this.scenarioDefinition); this.clearNodeStatus(this.$refs.stepTree.root.childNodes); this.sort(); + this.saved = runScenario && runScenario.stepScenario ? false : true; /*触发执行操作*/ this.$refs.currentScenario.validate(async (valid) => { if (valid) { diff --git a/frontend/src/business/components/api/automation/scenario/component/ApiComponent.vue b/frontend/src/business/components/api/automation/scenario/component/ApiComponent.vue index a122f1a555..af0887e90c 100644 --- a/frontend/src/business/components/api/automation/scenario/component/ApiComponent.vue +++ b/frontend/src/business/components/api/automation/scenario/component/ApiComponent.vue @@ -342,6 +342,7 @@ export default { }, methods: { forStatus() { + this.reqSuccess = true; if (this.request.result && this.request.result.length > 0) { this.request.result.forEach(item => { item.requestResult.forEach(req => { diff --git a/frontend/src/business/components/api/automation/scenario/component/ApiScenarioComponent.vue b/frontend/src/business/components/api/automation/scenario/component/ApiScenarioComponent.vue index 5135cd9548..5982271aa6 100644 --- a/frontend/src/business/components/api/automation/scenario/component/ApiScenarioComponent.vue +++ b/frontend/src/business/components/api/automation/scenario/component/ApiScenarioComponent.vue @@ -193,6 +193,7 @@ export default { this.scenario.run = true; let runScenario = JSON.parse(JSON.stringify(this.scenario)); runScenario.hashTree = [this.scenario]; + runScenario.stepScenario = true; this.$emit('runScenario', runScenario); }, formatResult(map, scenarios) { diff --git a/frontend/src/business/components/api/automation/scenario/component/LoopController.vue b/frontend/src/business/components/api/automation/scenario/component/LoopController.vue index 84b56a0125..5ec469ac6b 100644 --- a/frontend/src/business/components/api/automation/scenario/component/LoopController.vue +++ b/frontend/src/business/components/api/automation/scenario/component/LoopController.vue @@ -1,6 +1,6 @@