I have a HTTP request sampler with a response and a duration assertion. Now when the response assertion fails the next HTTP request sampler is not allowed to run. Only when the duration assertion fails the next HTTP request sampler is allowed to run.
I started doing this with an IF Controller
and checking ${JMeterThread.last_sample_ok}
but that was, when I only had the response assertion in place. When adding the duration assertion and the new requirement this no longer applied.
I have tried BeanShell Post Processors to add certain variables when the duration assertion fails. But the following code is always giving me back and empty array event when the duration assertion fails.
BeanShell Post 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 have also tried to use a BeanShell listener and this does give me back two assertions but when creating (putting) certain variables they aren't shown 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 even possible what I want?
Thanks in advance.
I managed to get it to work with a BeanShell Listener
. My first attempt to do it with a BeanShell post processor isn't possible because of the execution order. Post Processors are run before assertions. This is also the reason why the Debug Post Processor
didn't show the variables created in the BeanShell Listener.
So the code of my BeanShell Listener
is as follows:
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());
And in my IF Controller
I set the following condition:
${do_post_assertion_consumer_service_url}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With