4

I've made login process with the help of jmeter. In of of request samplers I'm expecting to get response code "401". I've added BeanShell Assertion

if (ResponseCode.equals("401") == true) { 
    SampleResult.setResponseOK();  
    SampleResult.setSuccessful(true);

}

And my Results Tree is looking like this now.

My question is - what i need to add to BeanShell in order to make child of the second sample green (passed) as well as it's parent sample?

Neil Lunn
  • 148,042
  • 36
  • 346
  • 317
neckobik
  • 307
  • 1
  • 6
  • 13

1 Answers1

6

The easiest way is using Response Assertion configured like:

Response Assertion


If you are still looking for Beanshell solution - you need to process all sub-results along with the main result so you should amend your code like:

import org.apache.jmeter.samplers.SampleResult;

//process main sample
if (SampleResult.getResponseCode().equals("401")) {
    SampleResult.setResponseCodeOK();
    SampleResult.setSuccessful(true);
}

//process all subsamples
for (SampleResult subResult : SampleResult.getSubResults()){
    if (subResult.getResponseCode().equals("401")){
        subResult.setResponseCodeOK();
        subResult.setSuccessful(true);
    }
}

See How to Use BeanShell: JMeter's Favorite Built-in Component article for more information on using Beanshell in JMeter test scripts.

Dmitri T
  • 159,985
  • 5
  • 83
  • 133
  • Thank you. It is exactly what I was looking for. – neckobik Nov 04 '16 at 11:19
  • Those who want to use not Beanshell, for groovy use `prev.setSuccessful(true)` for JS `sampleResult.setSuccessful(true)`. http://jmeter.apache.org/usermanual/functions.html – Alex Martian Feb 04 '20 at 12:51
  • Actually also line `import org.apache.jmeter.samplers.SampleResult;` is not needed and misleading as later `SampleResult` is variable from link in my prev comment, not that import, these functions are not static. That said, the answer helped me. – Alex Martian Feb 04 '20 at 13:07