Santosh sanwal
Santosh sanwal

Reputation: 154

How to set values of variable using postprocessor in Jmeter and use it in Preprocessor for same sampler?

My scenario is to pass different time (15 mins gap) till the script runs for each sampler run. I am using preprocessor and postprocessor in the same step and now i want to use the the variable changed in postprocessor step, in side post processor step. Below is the screenshot of code and script.

enter image description here

enter image description here

enter image description here

Upvotes: 1

Views: 1789

Answers (3)

Kamesh
Kamesh

Reputation: 11

Like mentioned above vars.put("","") wont work from post to preprocessor. There is way to sending the values from from post to pre processor by using Property in Jmeter using BeanShell

Inside the PostProcess

props.put("property_name", extractedValue);

and in the preprocessor

String value = props.getProperty("pageNumber");
if (value != null) {
  vars.put("my_variable", String.valueOf(retrievedValue));
}

Upvotes: 0

Dmitri T
Dmitri T

Reputation: 168157

  1. According to JMeter Test Elements Execution Order PreProcessor is executed before the PostProcessor therefore you cannot access the variables set in the PostProcessor in the PreProcessor
  2. There is __timeShift() function which can generate the date in the given format with the given offset, for example you can add 15 minutes to current time as simple as:

    ${__timeShift(yyyy-MM-dd'T'HH:mm:ss.SSS'Z',,PT15M,,)}
    
  3. There is no need to use these SimpleDateFormat/Calendar in Groovy, there is TimeCategory class which makes dates manipulation very easy. Moreover, Groovy's Date class provides format() function therefore you can add 15 minutes to the current date like:

    use(groovy.time.TimeCategory) {
        15.minutes.from.now.format("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'")
    }
    

Demo:

enter image description here

Upvotes: 1

Santosh sanwal
Santosh sanwal

Reputation: 154

Just found out the solution. I don't need to add preprocessor here. instead just using jsr223 sampler will work fine with onceonly controller. preprocessor was resetting the starttime and endtime value here.

Upvotes: 0

Related Questions