Scenario is: Generate 1 random float number in between 0.01 to 500 and pass it as var_1
Generate 1 more float number in range of 0.01 to 0.17 and save it as var_2
Now, whatever is the number picked up by JMeter as var_1, add var_2 to it ie: var_1+var_2 and pass it as var_3
I recall answering something similar here , however probably I missed the step of storing the values into JMeter Variables
In JMeter's Groovy you have vars
shorthand which stands for JMeterVariables class instance so you can use it to write generated values and their sum into the required variables like:
import org.apache.commons.lang3.RandomUtils
def float1 = RandomUtils.nextFloat(0.01f, 500f)
def float2 = RandomUtils.nextFloat(0.01f, 0.17f)
def sum = float1 + float2
vars.put('var_1', float1 as String)
vars.put('var_2', float2 as String)
vars.put('var_3', sum as String)
You can verify generated variables along with their values using Debug Sampler and View Results Tree Listener combination:
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.