如何获取JMeter线程组的总体PASS / FAIL结果

时间:2018-04-27 09:12:39

标签: jmeter performance-testing

如何在不使用每个采样器的后置处理器的情况下获得JMeter线程组的整体PASS / FAIL结果?

我尝试过使用beanhell监听器,但它不适用于事务控制器中有多个采样器的实例,其中包含"生成父样本"启用。在这种情况下,每个事务控制器只调用一次监听器,并且我只能访问事务控制器中最后一个采样器的结果。

编辑:

我希望能够将通过/失败值保存为线程组的Jmeter变量或属性。如果线程组的一个或多个组件发生故障或返回错误,那么这将是一个整体失败。然后,此变量将用于报告目的。

我当前的beanshell侦听器代码:

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 个答案:

答案 0 :(得分:0)

如果您致电prev.getParent(),您将可以通过getSubResults()功能获取单个子样本,例如:

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

演示:

JMeter Transaction Controller Children Time Groovy

更多信息:Apache Groovy - Why and How You Should Use It