Setting below sample result in jar file
mySampleResult.setResponseData("ReturnCode" + returnCode + "EndReturnCode" ,null);
copy the jar file in lib/ext
of JMeter
.
Create a project where Regular expression extractor
is attached to java request which calls runtest in jar file
Response string is below
ReturnCodeThu Feb 16 08:01:56 GMT 2017,Thu Feb 16 09:09:27 GMT 2017,0:1:7:31,98.74105EndReturnCode
Regular Expression Extractor
Reference Name: returnValue
Regular Expression: ReturnCode(.*?)EndReturnCode
Beanshell Code
${returnValue}
Error in Beanshell
Response message: org.apache.jorphan.util.JMeterException: Error invoking bsh method: eval In file: inline evaluation of: `` try { Thu Feb 16 08:01:56 GMT 2017,Thu Feb 16 09:09:27 GMT 2017,0:1:7:31,9 . . . '' Encountered "16" at line 4, column 13.
Please let me know that why I am getting this error.
Your ${returnValue}
statement is syntaxically incorrect, you need at least to surround it with quotation marks like "${returnValue}"
so Beanshell interpreter would treat it as a Java String
Going forward, just putting this statement inside the Beanshell Sampler doesn't make any sense, you should add some further processing, i.e:
return "${returnValue}";
- will set Beanshell Sampler result to this valueSampleResult.setResponseData("${returnValue}".getBytes());
- the same as above but using SampleResult shorthandprint("${returnValue}");
- output the value to STDOUTlog.info("${returnValue}");
- output the value to jmeter.log fileSee How to Use BeanShell: JMeter's Favorite Built-in Component for more information on using Beanshell in JMeter scripts