I have a such problem
Here is my User defined variables: https://i.sstatic.net/DTlU4.png
And here is my script from JSR223 PreProcessor:
def params = []
def attributes = [:]
Random random = new Random()
def int variantToStartFrom = Integer.parseInt(vars.get("START_FROM"))
def int increment = variantToStartFrom + Integer.parseInt(vars.get("INCREMENT"))
for (int i = 3; i <= 3; i++) {
for (int j = variantToStartFrom; j <= increment; j++) {
def attr = [:]
attr.put('location_id', i)
attr.put('variant_id', j)
attr.put('quantity', random.nextInt(100000))
params.add(attr)
}
}
attributes.put('items', params)
def json = new groovy.json.JsonBuilder(attributes)
vars.put("START_FROM", increment.toString())
sampler.addNonEncodedArgument("", json.toPrettyString(), "")
sampler.setPostBodyRaw(true)
As result I'm trying to run Thread group two times
My idea is to override my START_FROM
var in User Defined Variable so then new Thread group run will use START_FROM + 1
value
Is vars.put("START_FROM", increment.toString())
should work as I expected? Or is there any other way how to override User Defined Variable from script?
It works as expected. Your script will change the value of START_FROM
after running script, but it only happens while running. When test finish and re-run the test, STAT_FROM
will be back to value that defined in GUI, it's is 1.
To sum up, you can change the value while running test, you can't change the value you've already typed in GUI.