diff --git a/backend/src/main/java/io/metersphere/api/dto/definition/request/MsScenario.java b/backend/src/main/java/io/metersphere/api/dto/definition/request/MsScenario.java index b0ae06627b..104c568e6c 100644 --- a/backend/src/main/java/io/metersphere/api/dto/definition/request/MsScenario.java +++ b/backend/src/main/java/io/metersphere/api/dto/definition/request/MsScenario.java @@ -189,7 +189,7 @@ public class MsScenario extends MsTestElement { } }); } - if (config != null && config.getConfig() != null && config.getConfig().get(this.getProjectId()).getCommonConfig() != null + if (config != null && config.getConfig() != null && config.getConfig().get(this.getProjectId()) != null && config.getConfig().get(this.getProjectId()).getCommonConfig() != null && CollectionUtils.isNotEmpty(config.getConfig().get(this.getProjectId()).getCommonConfig().getVariables())) { config.getConfig().get(this.getProjectId()).getCommonConfig().getVariables().stream().filter(KeyValue::isValid).filter(KeyValue::isEnable).forEach(keyValue -> arguments.addArgument(keyValue.getName(), keyValue.getValue(), "=") diff --git a/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsHTTPSamplerProxy.java b/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsHTTPSamplerProxy.java index 726df485fe..1ce15e9f3d 100644 --- a/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsHTTPSamplerProxy.java +++ b/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsHTTPSamplerProxy.java @@ -114,7 +114,7 @@ public class MsHTTPSamplerProxy extends MsTestElement { sampler.setFollowRedirects(this.isFollowRedirects()); sampler.setUseKeepAlive(true); sampler.setDoMultipart(this.isDoMultipartPost()); - if (config != null && config.getConfig() != null) { + if (config != null && config.getConfig() != null && !config.getConfig().isEmpty()) { config.setConfig(config.getConfig()); } else { // 单独接口执行 diff --git a/backend/src/main/java/io/metersphere/api/service/ApiDefinitionService.java b/backend/src/main/java/io/metersphere/api/service/ApiDefinitionService.java index cf39bcd701..8f9a45da4b 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiDefinitionService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiDefinitionService.java @@ -13,6 +13,7 @@ import io.metersphere.api.dto.definition.parse.ApiDefinitionImportParserFactory; import io.metersphere.api.dto.definition.request.ParameterConfig; import io.metersphere.api.dto.definition.request.ScheduleInfoSwaggerUrlRequest; import io.metersphere.api.dto.definition.request.sampler.MsHTTPSamplerProxy; +import io.metersphere.api.dto.scenario.environment.EnvironmentConfig; import io.metersphere.api.dto.scenario.request.RequestType; import io.metersphere.api.dto.swaggerurl.SwaggerTaskResult; import io.metersphere.api.dto.swaggerurl.SwaggerUrlRequest; @@ -85,6 +86,8 @@ public class ApiDefinitionService { private ScheduleMapper scheduleMapper; @Resource private ApiTestCaseMapper apiTestCaseMapper; + @Resource + private ApiTestEnvironmentService environmentService; private static Cache cache = Cache.newHardMemoryCache(0, 3600 * 24); @@ -427,8 +430,21 @@ public class ApiDefinitionService { public String run(RunDefinitionRequest request, List bodyFiles) { List bodyUploadIds = new ArrayList<>(request.getBodyUploadIds()); FileUtils.createBodyFiles(bodyUploadIds, bodyFiles); + ParameterConfig config = new ParameterConfig(); config.setProjectId(request.getProjectId()); + + Map envConfig = new HashMap<>(); + Map map = request.getEnvironmentMap(); + if (map != null) { + map.keySet().forEach(id -> { + ApiTestEnvironmentWithBLOBs environment = environmentService.get(map.get(id)); + EnvironmentConfig env = JSONObject.parseObject(environment.getConfig(), EnvironmentConfig.class); + envConfig.put(id, env); + }); + config.setConfig(envConfig); + } + HashTree hashTree = request.getTestElement().generateHashTree(config); String runMode = ApiRunMode.DEFINITION.name(); if (StringUtils.isNotBlank(request.getType()) && StringUtils.equals(request.getType(), ApiRunMode.API_PLAN.name())) { diff --git a/frontend/src/business/components/api/automation/scenario/EditApiScenario.vue b/frontend/src/business/components/api/automation/scenario/EditApiScenario.vue index 25caf7618a..78ae9e667b 100644 --- a/frontend/src/business/components/api/automation/scenario/EditApiScenario.vue +++ b/frontend/src/business/components/api/automation/scenario/EditApiScenario.vue @@ -149,7 +149,7 @@ 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 2d8644c056..1bfc9ebdc0 100644 --- a/frontend/src/business/components/api/automation/scenario/component/ApiComponent.vue +++ b/frontend/src/business/components/api/automation/scenario/component/ApiComponent.vue @@ -16,7 +16,7 @@ {{ $t('commons.copy') }} {{ $t('api_test.scenario.reference') }} {{getProjectName(request.projectId)}} - @@ -84,7 +84,8 @@ default: false, }, currentEnvironmentId: String, - projectList: Array + projectList: Array, + envMap: Map }, components: { CustomizeReqInfo, @@ -249,13 +250,20 @@ this.reload(); }, run() { - if (!this.currentEnvironmentId) { - this.$error(this.$t('api_test.environment.select_environment')); - return; + if (!this.envMap || this.envMap.size === 0) { + this.$warning("请在环境配置中为该步骤所属项目选择运行环境!"); + return false; + } else if (this.envMap && this.envMap.size > 0) { + const env = this.envMap.get(this.request.projectId); + if (!env) { + this.$warning("请在环境配置中为该步骤所属项目选择运行环境!"); + return false; + } } this.request.active = true; this.loading = true; this.runData = []; + this.runData.projectId = this.request.projectId; this.request.useEnvironment = this.currentEnvironmentId; this.request.customizeReq = this.isCustomizeReq; let debugData = { diff --git a/frontend/src/business/components/api/automation/scenario/component/ComponentConfig.vue b/frontend/src/business/components/api/automation/scenario/component/ComponentConfig.vue index 12ed422f4e..4b5d93a5f2 100644 --- a/frontend/src/business/components/api/automation/scenario/component/ComponentConfig.vue +++ b/frontend/src/business/components/api/automation/scenario/component/ComponentConfig.vue @@ -2,7 +2,7 @@
+ @remove="remove" @copyRow="copyRow" @refReload="refReload" :project-list="projectList" :env-map="envMap"/>
@@ -28,7 +28,8 @@ currentEnvironmentId: String, response: {}, node: {}, - projectList: Array + projectList: Array, + envMap: Map }, data() { return { diff --git a/frontend/src/business/components/api/definition/components/Run.vue b/frontend/src/business/components/api/definition/components/Run.vue index e53b698131..d8d6d9ae85 100644 --- a/frontend/src/business/components/api/definition/components/Run.vue +++ b/frontend/src/business/components/api/definition/components/Run.vue @@ -2,7 +2,7 @@