0

Let's say I have a user-defined paramater bodies which is a space-delimited list of arbitrary length. I need to create a loop of HTTP requests based on the length of bodies and use its content.

For example if bodies=a b c, then I need to make a HTTP POST request using a in the header, then another using b in the header, and so on.

How can I do this in JMeter? So far, I've been able to use a JSR223 Sampler to set a variable NUM_ITERATIONS (would be 3 in this case), but I don't know how to loop using the correct parameter in each iteration.

ejtt
  • 363
  • 3
  • 10

1 Answers1

0

If you can control how does your "bodies" variable look like you could transform it into something like:

bodies_1=a
bodies_2=b
bodies_3=c

and use ForEach Controller to iterate all the elements.


One of the possible ways:

  1. Add Loop Controller to your Thread Group and put ${__groovy(vars.get('bodies').split(' ').size(),)} expression into "Loop Count" stanza
  2. Add HTTP Request sampler as a child of the Loop Controller
  3. Add HTTP Header Manager as a child of the HTTP Request sampler
  4. Refer the value from the user-defined parameter as

    ${__groovy(vars.get('bodies').split(' ')[vars.get('__jm__Loop Controller__idx') as int],)} 
    

    where required.

    JMeter Groovy Demo

References:

Dmitri T
  • 159,985
  • 5
  • 83
  • 133