From c6ac5055745301cfda7e1fb21255148b72493003 Mon Sep 17 00:00:00 2001 From: wxg0103 <727495428@qq.com> Date: Wed, 22 Feb 2023 18:57:47 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=8E=A5=E5=8F=A3=E5=AE=9A=E4=B9=89):=20?= =?UTF-8?q?=E4=BF=AE=E5=A4=8Dcase=E9=80=89=E6=8B=A9=E7=8E=AF=E5=A2=83?= =?UTF-8?q?=E7=BB=84=E6=89=A7=E8=A1=8C=E7=94=9F=E6=88=90=E6=8A=A5=E5=91=8A?= =?UTF-8?q?=E6=9C=89=E6=9C=AA=E6=89=A7=E8=A1=8C=E7=9A=84=E7=BC=BA=E9=99=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --bug=1023586 --user=王孝刚 【接口测试】场景中引用了case,选择环境组,执行场景后,这个case还是没有环境 https://www.tapd.cn/55049933/s/1340015 --- .../service/definition/ApiDefinitionService.java | 9 ++++++++- .../automation/scenario/component/ApiComponent.vue | 3 ++- .../frontend/src/business/definition/components/Run.vue | 3 +++ 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/api-test/backend/src/main/java/io/metersphere/service/definition/ApiDefinitionService.java b/api-test/backend/src/main/java/io/metersphere/service/definition/ApiDefinitionService.java index 59aea597fd..4692069c4b 100644 --- a/api-test/backend/src/main/java/io/metersphere/service/definition/ApiDefinitionService.java +++ b/api-test/backend/src/main/java/io/metersphere/service/definition/ApiDefinitionService.java @@ -31,6 +31,7 @@ import io.metersphere.commons.enums.*; import io.metersphere.commons.exception.MSException; import io.metersphere.commons.utils.*; import io.metersphere.dto.*; +import io.metersphere.environment.service.BaseEnvGroupProjectService; import io.metersphere.environment.service.BaseEnvironmentService; import io.metersphere.i18n.Translator; import io.metersphere.log.utils.ReflexObjectUtil; @@ -53,6 +54,7 @@ import io.metersphere.service.plan.TestPlanApiCaseService; import io.metersphere.service.scenario.ApiScenarioService; import io.metersphere.xpack.api.service.ApiCaseBatchSyncService; import io.metersphere.xpack.api.service.ApiDefinitionSyncService; +import jakarta.annotation.Resource; import org.apache.commons.beanutils.BeanComparator; import org.apache.commons.beanutils.BeanMap; import org.apache.commons.collections.CollectionUtils; @@ -73,7 +75,6 @@ import org.springframework.transaction.annotation.Transactional; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.multipart.MultipartFile; -import jakarta.annotation.Resource; import java.net.MalformedURLException; import java.util.*; import java.util.function.Function; @@ -162,6 +163,8 @@ public class ApiDefinitionService { private ApiDefinitionImportUtilService apiDefinitionImportUtilService; @Resource private BaseQuotaService baseQuotaService; + @Resource + private BaseEnvGroupProjectService environmentGroupProjectService; private static final String COPY = "Copy"; @@ -1943,6 +1946,10 @@ public class ApiDefinitionService { if (request.getConfig() == null) { request.setConfig(new RunModeConfigDTO()); } + + if (StringUtils.isNotBlank(request.getEnvironmentGroupId())) { + request.setEnvironmentMap(environmentGroupProjectService.getEnvMap(request.getEnvironmentGroupId())); + } // 验证是否本地执行 jMeterService.verifyPool(request.getProjectId(), request.getConfig()); if (!request.isDebug()) { diff --git a/api-test/frontend/src/business/automation/scenario/component/ApiComponent.vue b/api-test/frontend/src/business/automation/scenario/component/ApiComponent.vue index 47f030faad..b237e64fd9 100644 --- a/api-test/frontend/src/business/automation/scenario/component/ApiComponent.vue +++ b/api-test/frontend/src/business/automation/scenario/component/ApiComponent.vue @@ -450,7 +450,7 @@ export default { selectEnvId = store.scenarioEnvMap.get(this.currentScenario.id + '_' + this.request.projectId); this.environmentMap = this.envMap; } - if (!selectEnvId) { + if (!selectEnvId && !this.environmentGroupId) { this.$warning(this.$t('api_test.automation.env_message')); return false; } @@ -483,6 +483,7 @@ export default { headers: this.currentScenario.headers, enableCookieShare: this.enableCookieShare, environmentId: selectEnvId, + environmentGroupId: this.environmentGroupId, hashTree: [this.request], }; // 合并自身依赖场景变量 diff --git a/api-test/frontend/src/business/definition/components/Run.vue b/api-test/frontend/src/business/definition/components/Run.vue index 3273067877..05e66fd1cb 100644 --- a/api-test/frontend/src/business/definition/components/Run.vue +++ b/api-test/frontend/src/business/definition/components/Run.vue @@ -152,6 +152,9 @@ export default { if (this.runData[0].useEnvironment) { reqObj.environmentId = this.runData[0].useEnvironment; } + if (this.runData[0]) { + reqObj.environmentGroupId = this.runData[0].environmentGroupId; + } reqObj.reportId = this.reportId; if (!this.debug) { reqObj.syncResult = true;