fix(测试计划): 修复测试计划使用默认环境执行时,执行环境只会收到每个项目最后一个环境的问题

修复测试计划使用默认环境执行时,执行环境只会收到每个项目最后一个环境的问题
This commit is contained in:
song-tianyang 2023-02-22 17:56:41 +08:00 committed by 建国
parent 62662ba23d
commit 2dac3d91be
8 changed files with 567 additions and 356 deletions

View File

@ -26,6 +26,9 @@ public class RunModeConfigDTO {
* 运行环境 * 运行环境
*/ */
private Map<String, String> envMap; private Map<String, String> envMap;
//测试计划整体执行时的默认环境
private Map<String, List<String>> testPlanDefaultEnvMap;
private String environmentType; private String environmentType;
private String environmentGroupId; private String environmentGroupId;
//ui 测试 //ui 测试

View File

@ -15,7 +15,7 @@ public class TestPlanReportRunInfoDTO {
private String envGroupId; private String envGroupId;
private String runMode; private String runMode;
private Map<String, String> requestEnvMap; private Map<String, List<String>> requestEnvMap;
// <测试计划场景关联表ID, <项目ID环境ID>> // <测试计划场景关联表ID, <项目ID环境ID>>
private Map<String, Map<String, List<String>>> scenarioRunInfo; private Map<String, Map<String, List<String>>> scenarioRunInfo;

View File

@ -20,6 +20,7 @@ public class TestPlanRunRequest {
private boolean runWithinResourcePool;//是否选择资源池 private boolean runWithinResourcePool;//是否选择资源池
private String resourcePoolId;//资源池Id private String resourcePoolId;//资源池Id
private Map<String, String> envMap; private Map<String, String> envMap;
private Map<String, List<String>> testPlanDefaultEnvMap;
private String environmentType; private String environmentType;
private String environmentGroupId; private String environmentGroupId;
private List<String> testPlanIds; private List<String> testPlanIds;

View File

@ -271,7 +271,18 @@ public class TestPlanReportService {
List<TestPlanApiScenarioInfoDTO> scenarios) { List<TestPlanApiScenarioInfoDTO> scenarios) {
TestPlanReportRunInfoDTO runInfoDTO = new TestPlanReportRunInfoDTO(); TestPlanReportRunInfoDTO runInfoDTO = new TestPlanReportRunInfoDTO();
runInfoDTO.setRequestEnvMap(config.getEnvMap()); if (MapUtils.isNotEmpty(config.getEnvMap())) {
//判断记录选择的环境还是默认环境
Map<String, List<String>> requestEnvMap = new HashMap<>();
for (Map.Entry<String, String> entry : config.getEnvMap().entrySet()) {
requestEnvMap.put(entry.getKey(), new ArrayList<>() {{
this.add(entry.getValue());
}});
}
runInfoDTO.setRequestEnvMap(requestEnvMap);
} else {
runInfoDTO.setRequestEnvMap(config.getTestPlanDefaultEnvMap());
}
final Map<String, String> runEnvMap = MapUtils.isNotEmpty(config.getEnvMap()) ? config.getEnvMap() : new HashMap<>(); final Map<String, String> runEnvMap = MapUtils.isNotEmpty(config.getEnvMap()) ? config.getEnvMap() : new HashMap<>();
runInfoDTO.setRunMode(config.getMode()); runInfoDTO.setRunMode(config.getMode());
@ -1281,16 +1292,18 @@ public class TestPlanReportService {
} else { } else {
if (MapUtils.isNotEmpty(runInfoDTO.getRequestEnvMap())) { if (MapUtils.isNotEmpty(runInfoDTO.getRequestEnvMap())) {
Map<String, List<String>> projectEnvMap = new HashMap<>(); Map<String, List<String>> projectEnvMap = new HashMap<>();
for (Map.Entry<String, String> entry : runInfoDTO.getRequestEnvMap().entrySet()) { for (Map.Entry<String, List<String>> entry : runInfoDTO.getRequestEnvMap().entrySet()) {
String projectId = entry.getKey(); String projectId = entry.getKey();
String envId = entry.getValue(); List<String> envIdList = entry.getValue();
Project project = baseProjectService.getProjectById(projectId); Project project = baseProjectService.getProjectById(projectId);
String projectName = project == null ? null : project.getName(); String projectName = project == null ? null : project.getName();
String envNames = apiTestEnvironmentService.selectNameById(envId); if (StringUtils.isNotEmpty(projectName)) {
if (StringUtils.isNotEmpty(projectName) && StringUtils.isNotEmpty(envNames)) { List<String> envNameList = new ArrayList<>();
projectEnvMap.put(projectName, new ArrayList<>() {{ for (String envId : envIdList) {
this.add(envNames); String envName = apiTestEnvironmentService.selectNameById(envId);
}}); envNameList.add(envName);
}
projectEnvMap.put(projectName, envNameList);
} }
} }
if (MapUtils.isNotEmpty(projectEnvMap)) { if (MapUtils.isNotEmpty(projectEnvMap)) {

View File

@ -840,7 +840,7 @@ public class TestPlanService {
//环境参数为空时依据测试计划保存的环境执行 //环境参数为空时依据测试计划保存的环境执行
if (((StringUtils.equals("GROUP", runModeConfig.getEnvironmentType()) && StringUtils.isBlank(runModeConfig.getEnvironmentGroupId())) 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())) { && !StringUtils.equals(executionWay, ExecutionWay.RUN.name())) {
TestPlanWithBLOBs testPlanWithBLOBs = testPlanMapper.selectByPrimaryKey(testPlanId); TestPlanWithBLOBs testPlanWithBLOBs = testPlanMapper.selectByPrimaryKey(testPlanId);
if (StringUtils.isNotEmpty(testPlanWithBLOBs.getRunModeConfig())) { if (StringUtils.isNotEmpty(testPlanWithBLOBs.getRunModeConfig())) {
@ -853,6 +853,7 @@ public class TestPlanService {
Map<String, String> envMap = testPlanRunRequest.getEnvMap(); Map<String, String> envMap = testPlanRunRequest.getEnvMap();
String environmentGroupId = testPlanRunRequest.getEnvironmentGroupId(); String environmentGroupId = testPlanRunRequest.getEnvironmentGroupId();
runModeConfig = getRunModeConfigDTO(testPlanRunRequest, envType, envMap, environmentGroupId, testPlanId); runModeConfig = getRunModeConfigDTO(testPlanRunRequest, envType, envMap, environmentGroupId, testPlanId);
runModeConfig.setTestPlanDefaultEnvMap(testPlanRunRequest.getTestPlanDefaultEnvMap());
if (!testPlanRunRequest.isRunWithinResourcePool()) { if (!testPlanRunRequest.isRunWithinResourcePool()) {
runModeConfig.setResourcePoolId(null); runModeConfig.setResourcePoolId(null);
} }
@ -1637,6 +1638,7 @@ public class TestPlanService {
String environmentGroupId = testplanRunRequest.getEnvironmentGroupId(); String environmentGroupId = testplanRunRequest.getEnvironmentGroupId();
String testPlanId = testplanRunRequest.getTestPlanId(); String testPlanId = testplanRunRequest.getTestPlanId();
RunModeConfigDTO runModeConfig = getRunModeConfigDTO(testplanRunRequest, envType, envMap, environmentGroupId, testPlanId); RunModeConfigDTO runModeConfig = getRunModeConfigDTO(testplanRunRequest, envType, envMap, environmentGroupId, testPlanId);
runModeConfig.setTestPlanDefaultEnvMap(testplanRunRequest.getTestPlanDefaultEnvMap());
String apiRunConfig = JSON.toJSONString(runModeConfig); String apiRunConfig = JSON.toJSONString(runModeConfig);
return this.run(testPlanId, testplanRunRequest.getProjectId(), return this.run(testPlanId, testplanRunRequest.getProjectId(),

View File

@ -18,6 +18,7 @@
:has-option-group="true" :has-option-group="true"
:group-id="runConfig.environmentGroupId" :group-id="runConfig.environmentGroupId"
@setProjectEnvMap="setProjectEnvMap" @setProjectEnvMap="setProjectEnvMap"
@setDefaultEnv="setDefaultEnv"
@setEnvGroup="setEnvGroup" @setEnvGroup="setEnvGroup"
ref="envSelectPopover" ref="envSelectPopover"
class="mode-row" class="mode-row"
@ -249,6 +250,7 @@ export default {
testType: null, testType: null,
resourcePools: [], resourcePools: [],
projectEnvListMap: {}, projectEnvListMap: {},
defaultEnvMap: {},
runConfig: { runConfig: {
mode: "serial", mode: "serial",
reportType: "iddReport", reportType: "iddReport",
@ -261,6 +263,7 @@ export default {
retryEnable: false, retryEnable: false,
retryNum: 1, retryNum: 1,
browser: "CHROME", browser: "CHROME",
testPlanDefaultEnvMap: {},
}, },
projectList: [], projectList: [],
projectIds: new Set(), projectIds: new Set(),
@ -309,9 +312,11 @@ export default {
}, },
methods: { methods: {
open(testType, runModeConfig) { open(testType, runModeConfig) {
this.defaultEnvMap = {};
if (runModeConfig) { if (runModeConfig) {
this.runConfig = JSON.parse(runModeConfig); this.runConfig = JSON.parse(runModeConfig);
this.runConfig.envMap = new Map(); this.runConfig.envMap = new Map();
this.runConfig.testPlanDefaultEnvMap = {};
this.runConfig.onSampleError = this.runConfig.onSampleError =
this.runConfig.onSampleError === "true" || this.runConfig.onSampleError === "true" ||
this.runConfig.onSampleError === true; this.runConfig.onSampleError === true;
@ -368,6 +373,7 @@ export default {
this.$emit("close"); this.$emit("close");
}, },
handleRunBatch() { handleRunBatch() {
this.runConfig.testPlanDefaultEnvMap = this.defaultEnvMap;
this.$emit("handleRunBatch", this.runConfig); this.$emit("handleRunBatch", this.runConfig);
this.close(); this.close();
}, },
@ -376,6 +382,14 @@ export default {
this.resourcePools = response.data; this.resourcePools = response.data;
}); });
}, },
setDefaultEnv(projectId, envId) {
let ids = this.defaultEnvMap[projectId];
if (!ids) {
ids = [];
}
ids.push(envId);
this.defaultEnvMap[projectId] = ids;
},
setProjectEnvMap(projectEnvMap) { setProjectEnvMap(projectEnvMap) {
this.runConfig.envMap = projectEnvMap; this.runConfig.envMap = projectEnvMap;
}, },

View File

@ -264,6 +264,7 @@ export default {
}, },
initDefaultEnv() { initDefaultEnv() {
this.selectedEnvName = new Map(); this.selectedEnvName = new Map();
let defaultEnv = new Map();
this.evnList = []; this.evnList = [];
this.projectIds.forEach((d) => { this.projectIds.forEach((d) => {
let item = { let item = {
@ -307,7 +308,8 @@ export default {
} else { } else {
this.selectedEnvName.get(d).push(filter[0].name); this.selectedEnvName.get(d).push(filter[0].name);
} }
this.chooseEnv(filter[0].id);
this.$emit("setDefaultEnv", d, filter[0].id);
}); });
} }
} }