如何在 Jmeter 中提取响应字符串的出现次数,如果出现次数与数字不匹配,则测试失败?
How to extract number of occurances of a reponse string in Jmeter and fail the test if the occurances does not match a number?
我正在尝试计算 Jmeter 中响应的出现次数,如果计数不等于 4,则测试应该会失败。
我该怎么做?
我在 beanshell 断言中使用了这个:
Import org.apache.commons.lang3.StringUtils;
int matches = StringUtils.countMatches(new String(data), "itemname");
vars.put("ItemNameVar_matchNr", String.valueOf(matches));
assert matches == 5;
它。不管用。它显示错误:
Typed variable declaration : Undefined argument: data
- Beanshell 断言中没有
data
,有一个预定义变量ResponseData
,它是字节数组。
你在 Beanshell 中没有 assert
,你有 Failure
预定义的布尔值,它指示范围内的采样器是否应该成功。
完整代码:
import org.apache.commons.lang3.StringUtils;
int matches = StringUtils.countMatches(new String(ResponseData), "itemname");
vars.put("ItemNameVar_matchNr", String.valueOf(matches));
Failure = matches != 5;
参考文献:
我正在尝试计算 Jmeter 中响应的出现次数,如果计数不等于 4,则测试应该会失败。
我该怎么做?
我在 beanshell 断言中使用了这个:
Import org.apache.commons.lang3.StringUtils;
int matches = StringUtils.countMatches(new String(data), "itemname");
vars.put("ItemNameVar_matchNr", String.valueOf(matches));
assert matches == 5;
它。不管用。它显示错误:
Typed variable declaration : Undefined argument: data
- Beanshell 断言中没有
data
,有一个预定义变量ResponseData
,它是字节数组。 你在 Beanshell 中没有
assert
,你有Failure
预定义的布尔值,它指示范围内的采样器是否应该成功。完整代码:
import org.apache.commons.lang3.StringUtils; int matches = StringUtils.countMatches(new String(ResponseData), "itemname"); vars.put("ItemNameVar_matchNr", String.valueOf(matches)); Failure = matches != 5;
参考文献: