Kalpa-W
Kalpa-W

Reputation: 358

Group response from JMeter results

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

Answers (2)

Dmitri T
Dmitri T

Reputation: 168197

  1. Add a Beanshell PostProcessor as a child of the request which returns these abc or cde bits.
  2. 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
  • basing on whether response contains abc or cde parent sampler name will be changed accordingly (see image below for demo, "Dummy Sampler" becomes "abc" or "cde")
  • analyze results with the listener of your choice basing on sampler name

Beanshell PostProcessor in action

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

Nachiket Kate
Nachiket Kate

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

Related Questions