I need to calculate some dates in jmeter, so I created a BeanShell Pre Processor in my test structure:
- Thread Group
- Cache Manager
- Cookie Manager
- HTTP Header
- HTTP Manager
- IF controller (if the user could login)
- BeanShell Pre Processor
And my code it's like:
import java.text.SimpleDateFormat;
import java.util.Calendar;
try {
Calendar calendar = Calendar.getInstance();
SimpleDateFormat df= new SimpleDateFormat("yyyy-MM-dd'T'hh:mm:ssX");
long startTime = calendar.getTimeInMillis();
long endTime = Long.parseLong(vars.get("dateMiliseconds"));
randomStartDate = df.format(startTime + (long)(Math.random()*(endTime-startTime)));
randomEndDate = randomTime1 + (long)(Math.random()*(endTime - randomTime1)+86400000);
log.warn("startDate: "+randomStartDate+ " endDate: "+randomEndDate);
vars.put("RandomStartDate", randomStartDate);
vars.put("RandomEndDate", randomEndDate);
} catch (Exception e) {
log.warn("The error is: "+e);
throw e;
}
However when I ran the test Jmeter error says:
ERROR - jmeter.util.BeanShellInterpreter: Error invoking bsh method: eval Sourced file: inline evaluation of:
import java.text.SimpleDateFormat; import java.util.Calendar; try{ Calendar ca . . . :illegal use of undefined variable, class, or 'void' literalWARN - jmeter.modifiers.BeanShellPreProcessor: Problem in BeanShell script org.apache.jorphan.util.JMeterException: Error invoking bsh method: eval Sourced file: inline evaluation of:
import java.text.SimpleDateFormat; import java.util.Calendar; try{ Calendar ca . . .: illegal use of undefined variable, class, or 'void' literal
Any ideas? Thanks in advance