0
votes

I want to reset my counter at end of the each iteration of the loop. I implemented solution in my script like in the page Jmeter - Loop counter in while loop not resetting on exit but given solution is not working for me . I am using apache jmeter 5.1.1 version I added below code in JSR223 sampler out side the while controller within transaction controller

def counter=vars.get("counter"); ${__groovy(vars.put('counter'\, '2'),)}

Counter

enter image description here

Counter value is resetting but updated counter value not carrying to second iteration

logs: 2019-10-24 14:53:53,281 INFO o.a.j.p.j.s.J.JSR223 Sampler: counter value-----2

Placed JSR223 Sampler outside while controller/trasaction controller/loop controller.. In all the ways it is giving same response like below

enter image description here

I need result as

xrequest-1 

xrequest-2 

xrequest-3 

xrequest-4 

xrequest-5 

xrequest-6 

xrequest-7 

xrequest-8 . . . 

yrequest-1 

yrequest-2 

yrequest-3 

yrequest-4 

yrequest-5 

yrequest-6 . . .

Please help me if i am missing anything.

1

1 Answers

0
votes

You don't even need any Counter there.

Since JMeter 5.0 While Controller exposes a special JMeter Variable which looks like:

${__jm__While Controller__idx}

where While Controller needs to match the While Controller label.

So if you need to count iterations - you can just refer this variable. It's zero-based, to wit the value will be 0 at the first iteration, if you need the iteration number to start with 1 - go for __intSum() function like:

${__intSum(${__jm__While Controller__idx},1,)}

Demo:

enter image description here