My requirement was that whenever there was an error in the Jmeter execution, there should be a delay before starting the next iteration.
"Start Next Thread Loop" is selected at the Thread Group level for Sampler error. Due to this Jmeter will start a new Iteration if there is any error during the execution.
For this purpose I have used Beanshell Timer at the start of the Iteration. Following code is added for delay if the response code is anything other than "200"
String code = prev.getResponseCode();
if(code!="200"){
log.info("::::::::::::::::::::::::::::Response Code = "+code);
log.info("sleep for 10sec");
return 10000;
}
else
return 0;
Please let me know if there are any better ways of doing this.
I believe the prev.getResponseCode() can also be used to do any kind of cleanup task, in case there is any error.
Like for example, if a user logs into the application and got an error before doing logout. We can test at the start of the iteration if the previous response code is in error, if so, we can make the user logout of the application.
You can do this using:
${__jexl2("${JMeterThread.last_sample_ok}" == "false",)}
Test plan would have the following layout: