How is possible to peform multiple if then checks for the same variable in Jmeter ?I need to implement the following if then conditions in Jmeter:
if ${laiks} >=0 and ${laiks} <=85959 then ${OrderTime}=0
if ${laiks} >=90000 and ${laiks} <=105959 then ${OrderTime}=90000
if ${laiks} >=110000 and ${laiks} <=125959 then ${OrderTime}=110000
if ${laiks} >=130000 and ${laiks} <=152959 then ${OrderTime}=130000
if ${laiks} >=153000 and ${laiks} <=235959 then ${OrderTime}=153000
I created 5 IF controllers, each with its own condition, but Jmeter is always assigning last value 153000 to ${OrderTime} variable.
CodePudding user response:
If you need to create OrderTime
JMeter Variable based on laiks
variable value the easiest way of doing this is going for a suitable JSR223 Test Element and the following Groovy code:
switch (vars.get('laiks') as int) {
case 0..85959:
vars.put('OrderTime', '0')
break
case 90000..105959:
vars.put('OrderTime', '90000')
break
//etc
default:
vars.put('OrderTime', '-1')
}
More information on Groovy scripting in JMeter: Apache Groovy: What Is Groovy Used For?