I'm performing basic API testing of CRUD calls to the database. In JMeter, I have 1 thread with 3 thread groups within my test plan where I've set up Loops and Counters within each thread. The reason for Counters is when saving results to a file, I want to append the file's prefix with the counter value.
The issue is the counters never get reset. So for example:
Where Count = 1 for all groups, I would expect:
Thread Group 1, filename_1.json
Thread Group 2, filename_2.json
Thread Group 3, filename_3.xml
Where Group 1 Count = 3, Group 2 Count = 2, Group 3 Count = 1, I would expect:
Thread Group 1, filename_1.json, filename_2.json, filename_3.json
Thread Group 2, filename_4.json and filename_5.json
Thread Group 3, filename_6.xml
Instead, where Count = 1 for all groups I'm getting results like:
Thread Group 1, filename_11.json
Thread Group 2, filename_14.json
Thread Group 3, filename_18.xml
After much searching and trying multiple suggestions, I'm still not getting what I expect. Below is a sample of how the test plan is configured.
Any suggestions are much appreciated.
Thread Group 1
HTTP Header Manager (application/json)
Loop Controller
Counter (Start=1, Increment=1, Maximum=100, Num Format=null, Ref Name=LoopCounter1)
HTTP Request (CREATE)
RegEx (RefName=newRequest, Reg Ex = "id":(.+?)\,"displayName", Template=$1$, Match No.=1, Default=NONE)
BeanShell Assertion (Name=newRequest, Param=${__setProperty(newRequest,${newRequest},)})
Save Response to file (File prefix=requestResult_${LoopCounter}, Var Name=newRequestFile)
Loop Controller
HTTP Request (READ)
HTTP Request (UPDATE)
HTTP Request (DELETE)
Thread Group 2
HTTP Header Manager (application/json)
Loop Controller
Counter (Start=1, Increment=1, Maximum=100, Num Format=null, Ref Name=LoopCounter2)
HTTP Request (CREATE)
RegEx (RefName=newContractId, Reg Ex = "id":(.+?)\,"terminationType", Template=$1$, Match No.=1, Default=NONE)
BeanShell Assertion (Name=newContractId, Param=${__setProperty(newContractId,${newContractId},)})
Save Response to file (File prefix=contractRecords_${LoopCounter2}, Var Name=newContractFile)
Loop Controller
HTTP Request (READ)
HTTP Request (UPDATE)
HTTP Request (DELETE)
Thread Group 3
HTTP Header Manager (application/xml)
Loop Controller
Counter (Start=1, Increment=1, Maximum=100, Num Format=null, Ref Name=LoopCounter3)
HTTP Request (CREATE)
RegEx (RefName=newPricingId, Reg Ex = "id":(.+?)\,"terminationType", Template=$1$, Match No.=1, Default=NONE)
BeanShell Assertion (Name=newPricingId, Param=${__setProperty(newPricingId,${newPricingId},)})
Save Response to file (File prefix=pricingRecords_${LoopCounter3}, Var Name=newPricingFile)
Loop Controller
HTTP Request (READ)
HTTP Request (UPDATE)
HTTP Request (DELETE)
UPDATE
I'm closer to the desired results. With the "Reset counter on each Thread Group" enabled, I would expect Thread Group 2's Count to reset to 0. However, it continues from the previous thread. I need to reset the Counter within each Thread Group. Here's why:
Thread Group 2
HTTP Header Manager (application/json)
Loop Controller
Counter (Start=1, Increment=1, Maximum=100, Num Format=null, Ref Name=LoopCounter2)
HTTP POST Request (CREATE)
${__FileToString(${payloadArchive}/${__eval(contract_${LoopCounter})}.json,,)}
As you can see, I am passing in a different file into the HTTP Request's body with each loop of Thread Group 2. Each .json file contains unique elements based on the unique constraints of the database. The files are named "contract_01.json", "contract_02.json", "contract_03.json", etc. This is why I want Thread Group 2 to restart it's counter.