I am new to Jmeter. create a Jsr223 postprocessor and select language as Bsh.
import java.util.Date;
import java.text.SimpleDateFormat;
long mill = System.currentTimeMillis();
log.info(mill);
output:
ERROR - jmeter.extractor.JSR223PostProcessor: Problem in JSR223 script JSR223 PostProcessor javax.script.ScriptException: Sourced file: inline evaluation of: ``import java.util.Date; import java.text.SimpleDateFormat; long mill = System.c . . . '' : Error in method invocation: Method info( long ) not found in class'org.apache.log.Logger' : at Line: 5 : in file: inline evaluation of: ``import java.util.Date; import java.text.SimpleDateFormat; long mill = System.c . . . '' : log .info ( mill )
in inline evaluation of: ``import java.util.Date; import java.text.SimpleDateFormat; long mill = System.c . . . '' at line number 5
at bsh.engine.BshScriptEngine.evalSource(BshScriptEngine.java:92)
at bsh.engine.BshScriptEngine.eval(BshScriptEngine.java:46)
at javax.script.AbstractScriptEngine.eval(Unknown Source)
at org.apache.jmeter.util.JSR223TestElement.processFileOrScript(JSR223TestElement.java:206)
at org.apache.jmeter.extractor.JSR223PostProcessor.process(JSR223PostProcessor.java:42)
at org.apache.jmeter.threads.JMeterThread.runPostProcessors(JMeterThread.java:776)
at org.apache.jmeter.threads.JMeterThread.executeSamplePackage(JMeterThread.java:489)
at org.apache.jmeter.threads.JMeterThread.processSampler(JMeterThread.java:410)
at org.apache.jmeter.threads.JMeterThread.run(JMeterThread.java:241)
at java.lang.Thread.run(Unknown Source)
please advise a fix. thank you!
First of all, are you aware of __time() JMeter function which can output current time in the different formats?
If you still want to do it in Beanshell be informed that you cannot print a Long value directly to jmeter.log file, you need to cast it to String first using one of the following approaches
log.info(String.valueOf(mill));
log.info(Long.toString(mill));
log.info("Current time is: " + mill);
You can get a "good" Beanshell error by putting your code inside the try block like: