I am trying to count the number of occurrences of a response in Jmeter and if the count is not equal to 4, the test should fail.
How can i do that?
I used this in beanshell assertion:
Import org.apache.commons.lang3.StringUtils;
int matches = StringUtils.countMatches(new String(data), "itemname");
vars.put("ItemNameVar_matchNr", String.valueOf(matches));
assert matches == 5;
It. is not working. It shows error:
Typed variable declaration : Undefined argument: data
data
in the Beanshell Assertion, there is a pre-defined variable ResponseData
which is byte array. You don't have assert
in Beanshell, you have Failure
pre-defined boolean which indicates whether sampler(s) in scope should be successful or not.
Full code:
import org.apache.commons.lang3.StringUtils;
int matches = StringUtils.countMatches(new String(ResponseData), "itemname");
vars.put("ItemNameVar_matchNr", String.valueOf(matches));
Failure = matches != 5;
References: