fix(接口测试): 修复场景变量隔离就近取值原则问题

--bug=1011679 --user=赵勇 【接口测试】github#11932,场景变量和自定义脚本变量重名时,变量未生效 https://www.tapd.cn/55049933/s/1127365
This commit is contained in:
fit2-zhao 2022-03-30 10:07:04 +08:00 committed by fit2-zhao
parent b4359a6e80
commit aa0566092c
2 changed files with 26 additions and 1 deletions

View File

@ -36,6 +36,7 @@ import org.apache.jmeter.config.CSVDataSet;
import org.apache.jmeter.config.RandomVariableConfig;
import org.apache.jmeter.modifiers.CounterConfig;
import org.apache.jmeter.modifiers.JSR223PreProcessor;
import org.apache.jmeter.modifiers.UserParameters;
import org.apache.jmeter.protocol.http.sampler.HTTPSamplerProxy;
import org.apache.jmeter.save.SaveService;
import org.apache.jmeter.testelement.AbstractTestElement;
@ -592,6 +593,30 @@ public class ElementUtil {
return processor;
}
public static UserParameters argumentsToUserParameters(Arguments arguments) {
UserParameters processor = new UserParameters();
processor.setEnabled(true);
processor.setName("User Defined Variables");
processor.setPerIteration(true);
processor.setProperty(TestElement.TEST_CLASS, UserParameters.class.getName());
processor.setProperty(TestElement.GUI_CLASS, SaveService.aliasToClass("UserParametersGui"));
if (arguments != null && arguments.getArguments().size() > 0) {
List<String> names = new LinkedList<>();
List<Object> values = new LinkedList<>();
List<Object> threadValues = new LinkedList<>();
for (int i = 0; i < arguments.getArguments().size(); ++i) {
String argValue = arguments.getArgument(i).getValue();
String name = arguments.getArgument(i).getName();
names.add(name);
values.add(argValue);
}
processor.setNames(names);
threadValues.add(values);
processor.setThreadLists(threadValues);
}
return processor;
}
public static void setBaseParams(AbstractTestElement sampler, MsTestElement parent, ParameterConfig config, String id, String indexPath) {
sampler.setProperty("MS-ID", id);
sampler.setProperty("MS-RESOURCE-ID", ElementUtil.getResourceId(id, config, parent, indexPath));

View File

@ -146,7 +146,7 @@ public class MsScenario extends MsTestElement {
// 这里加入自定义变量解决ForEach循环控制器取值问题循环控制器无法从vars中取值
scenarioTree.add(valueSupposeMock);
if (this.variableEnable != null && this.variableEnable) {
scenarioTree.add(ElementUtil.argumentsToProcessor(valueSupposeMock));
scenarioTree.add(ElementUtil.argumentsToUserParameters(valueSupposeMock));
}
}
if (this.variableEnable == null || this.variableEnable) {