diff --git a/backend/src/main/java/io/metersphere/api/dto/definition/request/ElementUtil.java b/backend/src/main/java/io/metersphere/api/dto/definition/request/ElementUtil.java index 396229f5dc..1868fcfb42 100644 --- a/backend/src/main/java/io/metersphere/api/dto/definition/request/ElementUtil.java +++ b/backend/src/main/java/io/metersphere/api/dto/definition/request/ElementUtil.java @@ -101,6 +101,9 @@ public class ElementUtil { public static void addCsvDataSet(HashTree tree, List variables, ParameterConfig config, String shareMode) { if (CollectionUtils.isNotEmpty(variables)) { List list = variables.stream().filter(ScenarioVariable::isCSVValid).collect(Collectors.toList()); + if (CollectionUtils.isEmpty(list) && CollectionUtils.isNotEmpty(config.getTransferVariables())) { + list = config.getTransferVariables().stream().filter(ScenarioVariable::isCSVValid).collect(Collectors.toList()); + } if (CollectionUtils.isNotEmpty(list)) { list.forEach(item -> { CSVDataSet csvDataSet = new CSVDataSet(); 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 115a787cf6..a299c39579 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 @@ -136,6 +136,10 @@ public class MsScenario extends MsTestElement { this.setNewConfig(envConfig, newConfig); } + if (config != null && StringUtils.equals(this.getId(), config.getScenarioId())) { + config.setTransferVariables(this.variables); + } + if (config != null && !config.getExcludeScenarioIds().contains(this.getId())) { scenarioTree = MsCriticalSectionController.createHashTree(tree, this.getName(), this.isEnable()); } diff --git a/backend/src/main/java/io/metersphere/api/dto/definition/request/ParameterConfig.java b/backend/src/main/java/io/metersphere/api/dto/definition/request/ParameterConfig.java index 3ebeabdb67..7074c88c60 100644 --- a/backend/src/main/java/io/metersphere/api/dto/definition/request/ParameterConfig.java +++ b/backend/src/main/java/io/metersphere/api/dto/definition/request/ParameterConfig.java @@ -46,6 +46,10 @@ public class ParameterConfig extends MsParameter { * 公共场景参数 */ private List variables; + /** + * 当前场景变量,逐层传递 + */ + private List transferVariables; /** * 公共场景参数 diff --git a/backend/src/main/java/io/metersphere/api/exec/scenario/ApiScenarioExecuteService.java b/backend/src/main/java/io/metersphere/api/exec/scenario/ApiScenarioExecuteService.java index a4221c3d24..a2b620a2d2 100644 --- a/backend/src/main/java/io/metersphere/api/exec/scenario/ApiScenarioExecuteService.java +++ b/backend/src/main/java/io/metersphere/api/exec/scenario/ApiScenarioExecuteService.java @@ -320,6 +320,7 @@ public class ApiScenarioExecuteService { map = environmentGroupProjectService.getEnvMap(environmentGroupId); } ParameterConfig config = new ParameterConfig(); + config.setScenarioId(request.getScenarioId()); if (map != null) { apiScenarioEnvService.setEnvConfig(map, config); }