0
votes

How can I get an overall PASS/FAIL result for a JMeter thread group without using a post processor on every sampler?

I've tried using a beanshell listener, but it doesn't work for instances where there are multiple samplers inside a transaction controller with "Generate Parent Sample" enabled. In that case, the listener only gets called once per transaction controller and I'm only able to access the result of the last sampler inside the transaction controller.

Edit:

I would like to be able to save a pass/fail value as Jmeter variable or property for the thread group. If one or more components of the thread group fail or return an error, then that would be an overall fail. This variable will then be used for reporting purposes.

My current beanshell listener code:

SampleResult sr = ctx.getPreviousResult();

log.info(Boolean.toString(sr.isSuccessful()));

if (!sr.isSuccessful()){
    props.put("testPlanResult", "FAIL");

    testPlanResultComment = props.get("testPlanResultComment");

    if(testPlanResultComment == ""){
            testPlanResultComment = sr.getSampleLabel();
    }else {
            testPlanResultComment = testPlanResultComment + ", " + sr.getSampleLabel();
    }

    props.put("testPlanResultComment", testPlanResultComment);
    log.info(testPlanResultComment);
}
1
Please provide some more information/diagram/picture/code of what you are trying and what you want it to be like. Overall pass/fail is not very clear. - sunny_teo

1 Answers

0
votes

If you call prev.getParent() you will be able to fetch individual sub-samples via getSubResults() function, something like:

prev.getParent().getSubResults().each {result ->
    log.info('Sampler: ' + result.getSampleLabel() + ' Elapsed time: ' + result.getTime() )
}
log.info('Total: ' + prev.getParent().getTime())

Demo:

JMeter Transaction Controller Children Time Groovy

More information: Apache Groovy - Why and How You Should Use It