0

I have the following code construct in Jmeter:

Test Plan
- CSV Data config (reading in test reacords)
- Execution Thread
- - Do While (contains condition Counter < 5)
- - - Counter element (set to start at 1, increment by 1)
- - - Http request sending test record to api

The problem I am getting is that the Counter is not resetting after each test record is sent through, so the first record through works fine (5 iterations), the second stops at the first iteration.

I've tried: 1) Set counter in User defined variables 2) Reset counter element using a beanshell (this didn't work at all)

My test uses a single thread group with a single user thread. Each record in my csv file is only run through the system once.

How do I successfully reset the counter for each record?

1
  • Did you set "Reset counter on each Thread Group Iteration" checkbox? If that's not doing what you want, please provide more details Commented Aug 30, 2017 at 17:01

1 Answer 1

2
  1. If your "iterations" come from the Thread Group just do this:

    JMeter Counter Reset

  2. If your "iterations" are not driven by Thread Group and come from i.e. Loop Controller you can reset the counter by the following Groovy script:

    vars.put('Counter', '1')
    

    You can use the above script in any of JSR223 Test Elements or in __groovy() function available since JMeter 3.1. In the latter case you will need to escape the comma like:

    ${__groovy(vars.put('Counter'\, '1'),)} 
    
Sign up to request clarification or add additional context in comments.

1 Comment

Have applied both the flag settings and added the vars.put("Counter","1") into a beanshell sampler outside the While loop, but within the thread group. This seems to be working now. Thanks.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.