diff --git a/framework/sdk-parent/jmeter/src/main/java/io/metersphere/dto/RunModeConfigDTO.java b/framework/sdk-parent/jmeter/src/main/java/io/metersphere/dto/RunModeConfigDTO.java index 6cf1dce635..e0cc574739 100644 --- a/framework/sdk-parent/jmeter/src/main/java/io/metersphere/dto/RunModeConfigDTO.java +++ b/framework/sdk-parent/jmeter/src/main/java/io/metersphere/dto/RunModeConfigDTO.java @@ -26,6 +26,9 @@ public class RunModeConfigDTO { * 运行环境 */ private Map envMap; + + //测试计划整体执行时的默认环境 + private Map> testPlanDefaultEnvMap; private String environmentType; private String environmentGroupId; //ui 测试 diff --git a/test-track/backend/src/main/java/io/metersphere/plan/dto/TestPlanReportRunInfoDTO.java b/test-track/backend/src/main/java/io/metersphere/plan/dto/TestPlanReportRunInfoDTO.java index 1958806901..8a758608aa 100644 --- a/test-track/backend/src/main/java/io/metersphere/plan/dto/TestPlanReportRunInfoDTO.java +++ b/test-track/backend/src/main/java/io/metersphere/plan/dto/TestPlanReportRunInfoDTO.java @@ -15,7 +15,7 @@ public class TestPlanReportRunInfoDTO { private String envGroupId; private String runMode; - private Map requestEnvMap; + private Map> requestEnvMap; // <测试计划场景关联表ID, <项目ID,环境ID>> private Map>> scenarioRunInfo; diff --git a/test-track/backend/src/main/java/io/metersphere/plan/request/api/TestPlanRunRequest.java b/test-track/backend/src/main/java/io/metersphere/plan/request/api/TestPlanRunRequest.java index 4c273de168..8d3f58a35c 100644 --- a/test-track/backend/src/main/java/io/metersphere/plan/request/api/TestPlanRunRequest.java +++ b/test-track/backend/src/main/java/io/metersphere/plan/request/api/TestPlanRunRequest.java @@ -20,6 +20,7 @@ public class TestPlanRunRequest { private boolean runWithinResourcePool;//是否选择资源池 private String resourcePoolId;//资源池Id private Map envMap; + private Map> testPlanDefaultEnvMap; private String environmentType; private String environmentGroupId; private List testPlanIds; diff --git a/test-track/backend/src/main/java/io/metersphere/plan/service/TestPlanReportService.java b/test-track/backend/src/main/java/io/metersphere/plan/service/TestPlanReportService.java index b06e417008..d883398af6 100644 --- a/test-track/backend/src/main/java/io/metersphere/plan/service/TestPlanReportService.java +++ b/test-track/backend/src/main/java/io/metersphere/plan/service/TestPlanReportService.java @@ -271,7 +271,18 @@ public class TestPlanReportService { List scenarios) { TestPlanReportRunInfoDTO runInfoDTO = new TestPlanReportRunInfoDTO(); - runInfoDTO.setRequestEnvMap(config.getEnvMap()); + if (MapUtils.isNotEmpty(config.getEnvMap())) { + //判断记录选择的环境还是默认环境 + Map> requestEnvMap = new HashMap<>(); + for (Map.Entry entry : config.getEnvMap().entrySet()) { + requestEnvMap.put(entry.getKey(), new ArrayList<>() {{ + this.add(entry.getValue()); + }}); + } + runInfoDTO.setRequestEnvMap(requestEnvMap); + } else { + runInfoDTO.setRequestEnvMap(config.getTestPlanDefaultEnvMap()); + } final Map runEnvMap = MapUtils.isNotEmpty(config.getEnvMap()) ? config.getEnvMap() : new HashMap<>(); runInfoDTO.setRunMode(config.getMode()); @@ -1281,16 +1292,18 @@ public class TestPlanReportService { } else { if (MapUtils.isNotEmpty(runInfoDTO.getRequestEnvMap())) { Map> projectEnvMap = new HashMap<>(); - for (Map.Entry entry : runInfoDTO.getRequestEnvMap().entrySet()) { + for (Map.Entry> entry : runInfoDTO.getRequestEnvMap().entrySet()) { String projectId = entry.getKey(); - String envId = entry.getValue(); + List envIdList = entry.getValue(); Project project = baseProjectService.getProjectById(projectId); String projectName = project == null ? null : project.getName(); - String envNames = apiTestEnvironmentService.selectNameById(envId); - if (StringUtils.isNotEmpty(projectName) && StringUtils.isNotEmpty(envNames)) { - projectEnvMap.put(projectName, new ArrayList<>() {{ - this.add(envNames); - }}); + if (StringUtils.isNotEmpty(projectName)) { + List envNameList = new ArrayList<>(); + for (String envId : envIdList) { + String envName = apiTestEnvironmentService.selectNameById(envId); + envNameList.add(envName); + } + projectEnvMap.put(projectName, envNameList); } } if (MapUtils.isNotEmpty(projectEnvMap)) { diff --git a/test-track/backend/src/main/java/io/metersphere/plan/service/TestPlanService.java b/test-track/backend/src/main/java/io/metersphere/plan/service/TestPlanService.java index 5a181c32db..bd3f0e07d5 100644 --- a/test-track/backend/src/main/java/io/metersphere/plan/service/TestPlanService.java +++ b/test-track/backend/src/main/java/io/metersphere/plan/service/TestPlanService.java @@ -840,7 +840,7 @@ public class TestPlanService { //环境参数为空时,依据测试计划保存的环境执行 if (((StringUtils.equals("GROUP", runModeConfig.getEnvironmentType()) && StringUtils.isBlank(runModeConfig.getEnvironmentGroupId())) - || (!StringUtils.equals("GROUP", runModeConfig.getEnvironmentType()) && MapUtils.isEmpty(runModeConfig.getEnvMap()))) + || (!StringUtils.equals("GROUP", runModeConfig.getEnvironmentType()) && MapUtils.isEmpty(runModeConfig.getEnvMap()) && MapUtils.isEmpty(runModeConfig.getTestPlanDefaultEnvMap()))) && !StringUtils.equals(executionWay, ExecutionWay.RUN.name())) { TestPlanWithBLOBs testPlanWithBLOBs = testPlanMapper.selectByPrimaryKey(testPlanId); if (StringUtils.isNotEmpty(testPlanWithBLOBs.getRunModeConfig())) { @@ -853,6 +853,7 @@ public class TestPlanService { Map envMap = testPlanRunRequest.getEnvMap(); String environmentGroupId = testPlanRunRequest.getEnvironmentGroupId(); runModeConfig = getRunModeConfigDTO(testPlanRunRequest, envType, envMap, environmentGroupId, testPlanId); + runModeConfig.setTestPlanDefaultEnvMap(testPlanRunRequest.getTestPlanDefaultEnvMap()); if (!testPlanRunRequest.isRunWithinResourcePool()) { runModeConfig.setResourcePoolId(null); } @@ -1637,6 +1638,7 @@ public class TestPlanService { String environmentGroupId = testplanRunRequest.getEnvironmentGroupId(); String testPlanId = testplanRunRequest.getTestPlanId(); RunModeConfigDTO runModeConfig = getRunModeConfigDTO(testplanRunRequest, envType, envMap, environmentGroupId, testPlanId); + runModeConfig.setTestPlanDefaultEnvMap(testplanRunRequest.getTestPlanDefaultEnvMap()); String apiRunConfig = JSON.toJSONString(runModeConfig); return this.run(testPlanId, testplanRunRequest.getProjectId(), diff --git a/test-track/frontend/src/business/plan/common/TestPlanRunModeWithEnv.vue b/test-track/frontend/src/business/plan/common/TestPlanRunModeWithEnv.vue index 6835647d7a..53b71de162 100644 --- a/test-track/frontend/src/business/plan/common/TestPlanRunModeWithEnv.vue +++ b/test-track/frontend/src/business/plan/common/TestPlanRunModeWithEnv.vue @@ -18,6 +18,7 @@ :has-option-group="true" :group-id="runConfig.environmentGroupId" @setProjectEnvMap="setProjectEnvMap" + @setDefaultEnv="setDefaultEnv" @setEnvGroup="setEnvGroup" ref="envSelectPopover" class="mode-row" @@ -249,6 +250,7 @@ export default { testType: null, resourcePools: [], projectEnvListMap: {}, + defaultEnvMap: {}, runConfig: { mode: "serial", reportType: "iddReport", @@ -261,6 +263,7 @@ export default { retryEnable: false, retryNum: 1, browser: "CHROME", + testPlanDefaultEnvMap: {}, }, projectList: [], projectIds: new Set(), @@ -309,9 +312,11 @@ export default { }, methods: { open(testType, runModeConfig) { + this.defaultEnvMap = {}; if (runModeConfig) { this.runConfig = JSON.parse(runModeConfig); this.runConfig.envMap = new Map(); + this.runConfig.testPlanDefaultEnvMap = {}; this.runConfig.onSampleError = this.runConfig.onSampleError === "true" || this.runConfig.onSampleError === true; @@ -368,6 +373,7 @@ export default { this.$emit("close"); }, handleRunBatch() { + this.runConfig.testPlanDefaultEnvMap = this.defaultEnvMap; this.$emit("handleRunBatch", this.runConfig); this.close(); }, @@ -376,6 +382,14 @@ export default { this.resourcePools = response.data; }); }, + setDefaultEnv(projectId, envId) { + let ids = this.defaultEnvMap[projectId]; + if (!ids) { + ids = []; + } + ids.push(envId); + this.defaultEnvMap[projectId] = ids; + }, setProjectEnvMap(projectEnvMap) { this.runConfig.envMap = projectEnvMap; }, diff --git a/test-track/frontend/src/business/plan/components/TestPlanList.vue b/test-track/frontend/src/business/plan/components/TestPlanList.vue index b0b489472c..b7ebb88535 100644 --- a/test-track/frontend/src/business/plan/components/TestPlanList.vue +++ b/test-track/frontend/src/business/plan/components/TestPlanList.vue @@ -1,10 +1,13 @@