【问题标题】:Is there a way to check if a certain assertion has failed有没有办法检查某个断言是否失败
【发布时间】:2013-11-01 09:28:27
【问题描述】:

我有一个带有响应和持续时间断言的 HTTP 请求采样器。现在,当响应断言失败时,不允许运行下一个 HTTP 请求采样器。只有当持续时间断言失败时,才允许运行下一个 HTTP 请求采样器。

我开始使用IF Controller 并检查${JMeterThread.last_sample_ok} 进行此操作,但那是在我只有响应断言到位时。添加持续时间断言和新要求时,这不再适用。

我已尝试使用 BeanShell 后处理器在持续时间断言失败时添加某些变量。但是当持续时间断言失败时,以下代码总是给我返回空数组事件。

BeanShell 后处理器代码:

import org.apache.jmeter.assertions.AssertionResult;

AssertionResult[] results = prev.getAssertionResults();

if (results.length == 0) {
   vars.put("assertions_have_zero_length", "true"); 
}

//debug post processor shows the above variable.

我也尝试使用 BeanShell 侦听器,这确实给了我两个断言,但是在创建(放置)某些变量时,它们没有显示在调试后处理器中。

BeanShell 监听器代码:

import org.apache.jmeter.assertions.AssertionResult;

AssertionResult[] results = sampleResult.getAssertionResults();

System.out.println("Current counter value = " + results.length);

if (results.length == 0) {
  vars.put("assertions_have_zero_length", "true"); 
} else {
  vars.put("assertions_have_zero_length", "false"); 
}

//no assertion_have_zero_length variable shown in debug post processor.

我是不是做错了什么,甚至有可能是我想要的吗?

提前致谢。

【问题讨论】:

    标签: jmeter


    【解决方案1】:

    我设法让它与BeanShell Listener 一起工作。由于execution order,我第一次尝试使用BeanShell 后处理器是不可能的。后处理器在断言之前运行。这也是Debug Post Processor 没有显示在BeanShell Listener 中创建的变量的原因。

    所以我BeanShell Listener的代码如下:

    import org.apache.jmeter.assertions.AssertionResult;
    
    AssertionResult[] results = sampleResult.getAssertionResults();
    
    boolean skipPostAssertionConsumerService = false;
    
    for(int i =0; i<results.length; i++) { 
    
        AssertionResult result = results[i];
    
        boolean isResponseAssertion = result.getName().equals("Response Assertion - Is Not Authentication Failed");
        boolean resultHasFailed = result.isFailure() || result.isError();
    
         if(isResponseAssertion && resultHasFailed) { 
            skipPostAssertionConsumerService = true;
            break;
         } 
    }
    
    vars.put("do_post_assertion_consumer_service_url", (!skipPostAssertionConsumerService).toString());
    

    在我的IF Controller 中,我设置了以下条件:

    ${do_post_assertion_consumer_service_url}
    

    【讨论】:

      猜你喜欢
      • 2021-08-10
      • 1970-01-01
      • 2016-06-20
      • 1970-01-01
      • 1970-01-01
      • 2014-04-05
      • 2011-02-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多