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;