I am trying to extract the results from my JBDC Request sampler using Bean shell assertion
I added a beanshell assertion to my sampler to extract the results and I got an error while running it. The Code in question is :
if (!ResponseCode.equals("200") || vars.getObject("dataFromDB").size() == 0) {
FailureMessage = "!!!!!!!!!!! No connection to the database or data not
received !!!!!!!!!!!";
Failure = true;
prev.setStopThread(true):
}
Where dataFromDB is the result variable name of my JBDC Request Sampler
The Error is : Assertion failure message: org.apache.jorphan.util.JMeterException: Error invoking bsh method: eval
There are at least 2 problems with your code:
FailureMessage
definition should be at one line or you should concatenate 2 strings on 2 linesprev.setStopThread(true);
should end with the semicolon Additionally:
vars.getObject("dataFromDB")
expression doesn't produce null
Assuming all above the suggested fixes would look like:
try {
if (!ResponseCode.equals("200") || vars.getObject("dataFromDB").size() == 0) {
FailureMessage = "!!!!!!!!!!! No connection to the database or data notreceived !!!!!!!!!!!";
Failure = true;
prev.setStopThread(true);
}
} catch (Exception ex) {
log.error("Script failure", ex);
}
Be aware that since JMeter 3.1 it's recommended to use JSR223 Test Elements and Groovy language for any form of scripting so consider migrating to JSR223 Assertion, the required code amendments would look like:
if (!prev.getResponseCode().equals("200") || vars.getObject("dataFromDB").size() == 0) {
AssertionResult.setFailure(true);
AssertionResult.setFailureMessage("!!!!!!!!!!! No connection to the database or data notreceived !!!!!!!!!!!");
}