Reputation: 358
I am sending an HTTP request and its sending responses like 'abc' , 'cde' etc dynamically. How can I group and get the count of 'abc', 'cde' responses? I need to analyze the results based on the responses I am getting. Please advice.
Upvotes: 1
Views: 345
Reputation: 168197
abc
or cde
bits.Put the following code into the PostProcessor's "Script" area
String response = new String(data);
if (response.contains("abc")) {
prev.setSampleLabel("abc");
}
if (response.contains("cde")) {
prev.setSampleLabel("cde");
}
Explanation:
data
is a shorthand to byte-array containing parent sampler response data. prev
stands for the parent sampler SampleResult instance abc
or cde
parent sampler name will be changed accordingly (see image below for demo, "Dummy Sampler" becomes "abc" or "cde")See How to use BeanShell: JMeter's favorite built-in component guide for comprehensive information on Beanshell scripting, pre-defined variables reference and kind of Beanshell cookbook.
Upvotes: 0
Reputation: 8571
You can do it with the help of beanshell processor
example could be,
import org.springframework.util.StringUtils;
String Pattern1= "abc";
int countPattern1 = StringUtils.countOccurrencesOf(new String(data),Pattern1);
vars.put("Count_Pattern1", String.valueOf(countPattern1));
Here This is simple java code which is finding occurrences of string "abc" in Response of sampler (Which is present in data variable)
vars.put is finally returning the count of occurrences in Count_Pattern1 variable. You can write your logic in same beanshell or elsewhere like,
import org.springframework.util.StringUtils;
String Pattern1= "abc";
int countPattern1 = StringUtils.countOccurrencesOf(new String(data),Pattern1);
vars.put("Count_Pattern1", String.valueOf(countPattern1));
//Your logic
Upvotes: 1