JMeter BeanShell - 遍历值
JMeter BeanShell - Loop through values
我尝试使用数组中的变量作为 Path
用于 HTTP Request
。 Path
应该是这样的:mypath/${act_value}
String[] numbers = mylist.split(",");
String act_value;
for (int i = 1; i <= 25; i++) {
vars.put(numbers[i], act_value);
}
mylist
作为提取器的输出给出,逗号分隔的字符串:mylist=123,456,343,909
HTTP Request
state 无法访问这个变量,我得到错误:
java.net.URISyntaxException: Illegal character in path
将您的代码修改为:
String myList = "123,456,343,909";
String[] numbers = myList.split(",");
for (int i = 0; i < numbers.length; i++) {
vars.put("number_" + i, numbers[i]);
}
在这个脚本后的某处添加ForEach Controller,配置如下:
- 输入变量前缀:
number
- 输出变量名:
act_value
将您的 HTTP Request 采样器作为 ForEach 控制器的子级
您的 HTTP 请求将针对 myList
中的每个值执行
同时考虑切换到 JSR223 Test Elements and Groovy language,在大多数情况下,有效的 Beanshell 代码将是有效的 Groovy 代码,但性能会高得多。
我尝试使用数组中的变量作为 Path
用于 HTTP Request
。 Path
应该是这样的:mypath/${act_value}
String[] numbers = mylist.split(",");
String act_value;
for (int i = 1; i <= 25; i++) {
vars.put(numbers[i], act_value);
}
mylist
作为提取器的输出给出,逗号分隔的字符串:mylist=123,456,343,909
HTTP Request
state 无法访问这个变量,我得到错误:
java.net.URISyntaxException: Illegal character in path
将您的代码修改为:
String myList = "123,456,343,909"; String[] numbers = myList.split(","); for (int i = 0; i < numbers.length; i++) { vars.put("number_" + i, numbers[i]); }
在这个脚本后的某处添加ForEach Controller,配置如下:
- 输入变量前缀:
number
- 输出变量名:
act_value
- 输入变量前缀:
将您的 HTTP Request 采样器作为 ForEach 控制器的子级
您的 HTTP 请求将针对
中的每个值执行myList
同时考虑切换到 JSR223 Test Elements and Groovy language,在大多数情况下,有效的 Beanshell 代码将是有效的 Groovy 代码,但性能会高得多。