fix(接口测试): 修复场景变量CSV在循环中只取值重复问题

--bug=1011867 --user=赵勇 【接口测试】github#12201,在A场景里引用B场景,B场景如果放在A场景上面,且B场景里有用到场景变量,这个时候再执行,循环取出来的值都是一样的 https://www.tapd.cn/55049933/s/1129135
This commit is contained in:
fit2-zhao 2022-04-01 18:39:06 +08:00 committed by 刘瑞斌
parent 55be24b582
commit 69a0b46f00
4 changed files with 12 additions and 0 deletions

View File

@ -101,6 +101,9 @@ public class ElementUtil {
public static void addCsvDataSet(HashTree tree, List<ScenarioVariable> variables, ParameterConfig config, String shareMode) { public static void addCsvDataSet(HashTree tree, List<ScenarioVariable> variables, ParameterConfig config, String shareMode) {
if (CollectionUtils.isNotEmpty(variables)) { if (CollectionUtils.isNotEmpty(variables)) {
List<ScenarioVariable> list = variables.stream().filter(ScenarioVariable::isCSVValid).collect(Collectors.toList()); List<ScenarioVariable> 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)) { if (CollectionUtils.isNotEmpty(list)) {
list.forEach(item -> { list.forEach(item -> {
CSVDataSet csvDataSet = new CSVDataSet(); CSVDataSet csvDataSet = new CSVDataSet();

View File

@ -136,6 +136,10 @@ public class MsScenario extends MsTestElement {
this.setNewConfig(envConfig, newConfig); 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())) { if (config != null && !config.getExcludeScenarioIds().contains(this.getId())) {
scenarioTree = MsCriticalSectionController.createHashTree(tree, this.getName(), this.isEnable()); scenarioTree = MsCriticalSectionController.createHashTree(tree, this.getName(), this.isEnable());
} }

View File

@ -46,6 +46,10 @@ public class ParameterConfig extends MsParameter {
* 公共场景参数 * 公共场景参数
*/ */
private List<ScenarioVariable> variables; private List<ScenarioVariable> variables;
/**
* 当前场景变量逐层传递
*/
private List<ScenarioVariable> transferVariables;
/** /**
* 公共场景参数 * 公共场景参数

View File

@ -320,6 +320,7 @@ public class ApiScenarioExecuteService {
map = environmentGroupProjectService.getEnvMap(environmentGroupId); map = environmentGroupProjectService.getEnvMap(environmentGroupId);
} }
ParameterConfig config = new ParameterConfig(); ParameterConfig config = new ParameterConfig();
config.setScenarioId(request.getScenarioId());
if (map != null) { if (map != null) {
apiScenarioEnvService.setEnvConfig(map, config); apiScenarioEnvService.setEnvConfig(map, config);
} }