Is there any way to check if any statement failed

I have an HTTP request sampler with a response and duration assertion. Now that the approval of the response failed, the next HTTP request sampler is not allowed. Only when the duration statement is not performed is the next HTTP sample request allowed to start.

I started to do this with help IF Controllerand verification ${JMeterThread.last_sample_ok}, but that was when I had only an approval of the answer in place. When adding a duration statement and a new requirement, this no longer applies.

I tried BeanShell Post Processors to add some variables when the duration statement fails. But the following code always returns me an empty array event when the duration statement does not work.

BeanShell mail processor code:

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.

I also tried using the BeanShell listener, and this returns two statements to me, but when I create (put) certain variables, they do not appear in the debug post processor.

BeanShell Listener Code:

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.

Am I doing something wrong and is it possible that I want to?

Thanks in advance.

+4
source share
1 answer

BeanShell Listener. BeanShell - . . , Debug Post Processor , BeanShell.

, 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}
+5

All Articles