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

修复测试计划使用默认环境执行时,执行环境只会收到每个项目最后一个环境的问题
This commit is contained in:
song-tianyang 2023-02-22 17:56:41 +08:00 committed by 建国
parent 23788673a9
commit 959f67c1c8
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, List<String>> testPlanDefaultEnvMap;
private String environmentType;
private String environmentGroupId;
//ui 测试

View File

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

View File

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

View File

@ -271,7 +271,18 @@ public class TestPlanReportService {
List<TestPlanApiScenarioInfoDTO> scenarios) {
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<>();
runInfoDTO.setRunMode(config.getMode());
@ -1281,16 +1292,18 @@ public class TestPlanReportService {
} else {
if (MapUtils.isNotEmpty(runInfoDTO.getRequestEnvMap())) {
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 envId = entry.getValue();
List<String> 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<String> envNameList = new ArrayList<>();
for (String envId : envIdList) {
String envName = apiTestEnvironmentService.selectNameById(envId);
envNameList.add(envName);
}
projectEnvMap.put(projectName, envNameList);
}
}
if (MapUtils.isNotEmpty(projectEnvMap)) {

View File

@ -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<String, String> 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(),

View File

@ -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;
},

View File

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