vlatko606
vlatko606

Reputation: 1149

Jmeter - Usage of item based on the condition

I have defined multiple countries at user defined variables as list:

enter image description here

Then in another sample i use specific country as ex: PL

What is the easiest way, based of the usage of specific country, to enter in the loop?

I know with ${__groovy(vars.get("countries") == "AR")} is possible to compare with 1 country, but how can i compare extracted country with all the countries in the list?

enter image description here

Upvotes: 1

Views: 41

Answers (1)

Dmitri T
Dmitri T

Reputation: 167992

If you need to iterate all the countries it's better to go for the ForEach Controller, in this case you need to transform the countries variable into the following pattern:

  • country_1=PL
  • country_2=PT
  • country_3=RO
  • etc.

If you're looking for a Groovy code to do the conversion:

  1. Add JSR223 Sampler at the place where you need to "enter the loop"
  2. Put the following code into "Script" area:

    vars.get('countries').trim().split(' ').eachWithIndex { country, index ->
        vars.put('country_' + ++index, country.trim())
    }
    
  3. Add ForEach Controller after the JSR223 Sampler and configure it like:

    enter image description here

  4. That's it, you should be able to iterate all the countries, defined in the countries variable

    enter image description here

Upvotes: 1

Related Questions