Variable value not updated in each iteration in Jmeter

Viewed 554

I am using timestamp as a value in my script to keep it unique and distinguishable in each of the iterations. I am using ${__time(/1)} function and storing it in the user defined variable inside a transaction controller and later using same variable in other transactions and json payload as well. This works well for single iteration.

I expected that in each iteration timestamp will be updated. but I can see that in each iteration same timestamp is being used. How could I make it updating timestamp in every iteration as I need to use only one timestamp value in an iteration and not repeating in successive iterations. using user defined variables with timestamp function

output

same value in each iteration

3 Answers

The User-Defined Variable config element is processed only once at the start. It is processed after the test plan. It is not suitable for your use case.

UDVs should not be used with functions that generate different results each time they are called. Only the result of the first function call will be saved in the variable.

There could be a number of options.

  1. Using User Parameters Pre-processor enter image description here

You may set the Update Once Per Iteration to suit your requirement.

  1. Using Set Variables Action plugin

enter image description here

  1. Set the value in JSR223 Pre-processor You may place the controller below the Test Plan.

enter image description here

As per User Defined Variables documentation:

Note that all the UDV elements in a test plan - no matter where they are - are processed at the start.

So the variable is evaluated only once, when the test starts, if you want it to return you the current timestamp each time it's called - just use __time() function directly where required, there is no need to declare it as the variable.

More information on JMeter Functions concept: Apache JMeter Functions - An Introduction

I also don't think that /1 bit in your ${__time(/1)} function does anything meaningful, maybe it worth considering removing it completely

Adding value to a variable will save time only once on load, you can put the time function inside payload to get different times

Another option is to use pre processor as User Parameters over User Defined Variables

For defining variables during a test run, seeĀ User Parameters. UDVs are processed in the order they appear in the Plan, from top to bottom

Related