Saagar
Saagar

Reputation: 834

JMeter ForEach controller with list of Objects not being iterated over

Following is my test plan. Where ForEach controller should loop through all the task Ids stored in user defined variable "userTaskIds". I tried defining list with both def myList = [] and List<Object> listId = new ArrayList<Object>();. In both the case its failed to loop. enter image description here ForEach controller not looping with "userTaskIds" variable. Here i tried with/without "add "_" before number ?"

enter image description here

Following are debug sampler result and Log view panel enter image description here

Log View

enter image description here

Upvotes: 2

Views: 8117

Answers (1)

UBIK LOAD PACK
UBIK LOAD PACK

Reputation: 34536

This is because ForEach Controller expects this:

  • userTaskIds_1
  • userTaskIds_2
  • ...

And

  • userTaskIds_matchNr = number of occurences

So in your JSR223 script you need to do this in each loop iteration :

Replace responseJSON.each by

  responseJSON.eachWithIndex {
     it, iterationLoop ->

Then

vars.put("userTaskIds_"+(iterationLoop+1), ""+it.id)

where iterationLoop must start with 1 and be incremented.

and after loop:

vars.put("userTaskIds_matchNr", Integer.toString(myList.size()));

Upvotes: 3

Related Questions