Search code examples
groovyjmeterunix-timestamp

2 different unix time stamp is generated when JSR223 Pre Processor is used in Jmeter


Here is the groovy code used in Jmeter JSR223 preprocessor:

import java.lang.Long
def long timeStamp=System.currentTimeMillis();
def name=("Report_"+timeStamp);
log.info(name)
vars.put("DocumentName",name);

I need to generate the first hit timestamp(single) and pass it to 2 different transaction. But when I checked jmeter log, it has 2 different timestamp that has been passed to 2 different transaction.

The same I have checked with SOAPUI tool but it gives me single output.


Solution

    1. Make sure you place Pre processor according to Jmeter scoping rules
    2. If you keep JSR223 Pre processor to the test plan level, it will be called before each sampler, thats the reason why you are getting different values..
    3. remove Pre processor from thread group/ test plan level and keep it as a child of the first sampler in transaction 1. so that Pre processor executed only once. as shown below. For more information on advanced JMeter scripting please follow this link

    enter image description here

    You can see in the results tree same value is being passed

    enter image description here