diff --git a/backend/src/main/java/io/metersphere/track/controller/TestPlanController.java b/backend/src/main/java/io/metersphere/track/controller/TestPlanController.java index 71e5bf3fca..63df1d48fd 100644 --- a/backend/src/main/java/io/metersphere/track/controller/TestPlanController.java +++ b/backend/src/main/java/io/metersphere/track/controller/TestPlanController.java @@ -214,6 +214,12 @@ public class TestPlanController { return testPlanService.runPlan(testplanRunRequest); } + @PostMapping("/run/save") + public String runAndSave(@RequestBody TestPlanRunRequest testplanRunRequest) { + testPlanService.updateRunModeConfig(testplanRunRequest); + return testPlanService.runPlan(testplanRunRequest); + } + @PostMapping(value = "/run/batch") @MsAuditLog(module = OperLogModule.TRACK_TEST_PLAN, type = OperLogConstants.EXECUTE, content = "#msClass.getLogDetails(#request.testPlanIds)", msClass = TestPlanService.class) public void runBatch(@RequestBody TestPlanRunRequest request) { diff --git a/backend/src/main/java/io/metersphere/track/service/TestPlanService.java b/backend/src/main/java/io/metersphere/track/service/TestPlanService.java index 536639375d..8ac52270e5 100644 --- a/backend/src/main/java/io/metersphere/track/service/TestPlanService.java +++ b/backend/src/main/java/io/metersphere/track/service/TestPlanService.java @@ -967,30 +967,27 @@ public class TestPlanService { LogUtil.error(e); } if (runModeConfig == null) { + runModeConfig = buildRunModeConfigDTO(); + } + + //环境参数为空时,依据测试计划保存的环境执行 + if ((StringUtils.equals("GROUP", runModeConfig.getEnvironmentType()) && StringUtils.isBlank(runModeConfig.getEnvironmentGroupId())) + || (!StringUtils.equals("GROUP", runModeConfig.getEnvironmentType()) && MapUtils.isEmpty(runModeConfig.getEnvMap()))) { TestPlanWithBLOBs testPlanWithBLOBs = testPlanMapper.selectByPrimaryKey(testPlanID); if (StringUtils.isNotEmpty(testPlanWithBLOBs.getRunModeConfig())) { - JSONObject json = JSONObject.parseObject(testPlanWithBLOBs.getRunModeConfig()); - TestPlanRequestUtil.changeStringToBoolean(json); - TestPlanRunRequest testPlanRunRequest = JSON.toJavaObject(json, TestPlanRunRequest.class); - if (StringUtils.equals("GROUP", testPlanRunRequest.getEnvironmentType()) && StringUtils.isBlank(testPlanRunRequest.getEnvironmentGroupId())) { - runModeConfig = buildRunModeConfigDTO(); - } else { - runModeConfig = new RunModeConfigDTO(); - runModeConfig.setMode(testPlanRunRequest.getMode()); - runModeConfig.setReportType(testPlanRunRequest.getReportType()); - if (testPlanRunRequest.getEnvMap() == null) { - runModeConfig.setEnvMap(new HashMap<>()); - } else { - runModeConfig.setEnvMap(testPlanRunRequest.getEnvMap()); + try { + JSONObject json = JSONObject.parseObject(testPlanWithBLOBs.getRunModeConfig()); + TestPlanRequestUtil.changeStringToBoolean(json); + TestPlanRunRequest testPlanRunRequest = JSON.toJavaObject(json, TestPlanRunRequest.class); + if (testPlanRunRequest != null) { + String envType = testPlanRunRequest.getEnvironmentType(); + Map envMap = testPlanRunRequest.getEnvMap(); + String environmentGroupId = testPlanRunRequest.getEnvironmentGroupId(); + runModeConfig = getRunModeConfigDTO(testPlanRunRequest, envType, envMap, environmentGroupId, testPlanID); } - runModeConfig.setOnSampleError(testPlanRunRequest.isOnSampleError()); + } catch (Exception e) { + LogUtil.error("获取测试计划保存的环境信息出错!", e); } - } else { - runModeConfig = buildRunModeConfigDTO(); - } - } else { - if (runModeConfig.getEnvMap() == null) { - runModeConfig.setEnvMap(new HashMap<>()); } } if (planReportId == null) { @@ -1980,7 +1977,6 @@ public class TestPlanService { String testPlanId = testplanRunRequest.getTestPlanId(); RunModeConfigDTO runModeConfig = getRunModeConfigDTO(testplanRunRequest, envType, envMap, environmentGroupId, testPlanId); String apiRunConfig = JSONObject.toJSONString(runModeConfig); - updatePlan(testplanRunRequest, testPlanId); return this.run(testPlanId, testplanRunRequest.getProjectId(), testplanRunRequest.getUserId(), testplanRunRequest.getTriggerMode(), testplanRunRequest.getReportId(), apiRunConfig); diff --git a/frontend/src/business/components/track/plan/components/TestPlanList.vue b/frontend/src/business/components/track/plan/components/TestPlanList.vue index e958a8fc1c..34db719a50 100644 --- a/frontend/src/business/components/track/plan/components/TestPlanList.vue +++ b/frontend/src/business/components/track/plan/components/TestPlanList.vue @@ -788,7 +788,7 @@ export default { param.requestOriginator = "TEST_PLAN"; if (config.isRun === true) { this.$refs.taskCenter.open(); - this.result = this.$post('test/plan/run/', param, () => { + this.result = this.$post('test/plan/run/save', param, () => { this.$success(this.$t('commons.run_success')); }); } else {