Search code examples
jmeterperformance-testing

Jmeter - How do I reset counter under a for each controller?


I am hitting the http request that has 2 dynamic variables under for each controller.

  1. One Variable value is from for each controller and another one is from Jmeter counter function variable- looks like this -${hostResponse}/${_V(account${__counter(,)})}
  2. I am performing multiple url requests from csv file and here, for first row request, the hostReponse and account-counter values are iterating and updating correctly up to 18 times as per my requirement.
  3. Now for 2nd row of request-the account-counter value is not resetting and starting from first. It is continuing as account_19,account_20,account_21....

As I am newbie to Jmeter,can someone suggest the idea on resetting the counter variable after every complete iteration.

Here is the test plan structure


Solution

  • __counter() function generates an incremented number each time it's being called therefore you either need to pass another argument to store the generated number into a separate JMeter Variable like:

    ${__counter(,counter2)}
    

    and then reference the value as ${counter2} where required

    or even remove this function completely as ForEach Controller is exposing its current iteration via ${__jm__ForEach Controller__idx} since JMeter 4.0

    enter image description here