counter, loop controller & foreach loop controller in jmeter

27 Views Asked by At

facing a problem as below

  1. I have a http request & in response header, I am getting a key, value as range: items=0-99/3876. how to extract the range 0,99 & 3876 as jmeter variable from postprocessor (like regular expression).

  2. I want to create a loop which runs for like 39 times (which is like round to the no 3876) to next 100/1000's to vary the range as 0-99,100-199, ... to 3800-3900.. for next http requests in loop with the counter. which increments by value of 100.

I have gone with the below procedure:-

  1. http sampler to get the response header :- range: items=0-99/3846
  2. extracted the values 0,99 & 3846 as jmeter values from different regular expressions extractor (which should have been done by single processor only)
  3. Want to get the loop count value as 3846/100 == 38 +1
  4. Now setting the counter with starting range as 0 with increment value of 100 & ending range as 99 with increment as 100 from the jmeter variables.
  5. now implement the counter variables as http header foe all the next headers.
1

There are 1 best solutions below

0
Ivan G On

Given you have the following JMeter Variables:

foo=0
bar=99
baz=3846

you can use __jexl3() function to calculate dynamic number of loops like:

${__jexl3(${baz}/100+1,)}

the function can be placed directly to the Loop Controller's "Loop Count" input:

enter image description here

this way given your data Loop Controller will run its children 39 times.

If you want to configure a Counter it would be something like:

enter image description here

See How to Use a Counter in a JMeter Test article for more details if needed.

The variable declared in the Counter can be used in the HTTP Header Manager:

enter image description here