How to access data inside foreach controller Jmeter

473 views Asked by At

How to access data inside foreach controller using JSR223 sampler with index value. For example

 data_1 = something

 data_2 = something

etc.

Whenever I tried using counter, it gives only data_1 for every count but in treeview I see that counter is working properly. How can I access every item in foreach controller.

2

There are 2 answers

0
Dmitri T On

What "data" do you want to access?

If you configure ForEach Controller like:

enter image description here

then you will be able to get the current value of foo variable as:

vars.get('foo')

Current iteration of the ForEach Controller can be accessed as:

vars.get('__jm__your-foreach-controller-name-here__idx')

if you haven't changed the default name it would be:

vars.get('__jm__ForEach Controller__idx')

Where vars is a shorthand for JMeterVariables class instance, see Top 8 JMeter Java Classes You Should Be Using with Groovy article for more details on this and other JMeter API shorthands.

0
Jatin On

Jus for you reference, I have completed my task as mentioned in below URL (which is my question) using approach 2.

Foreach controller not working for Json data

Now I am able to get every each json object inside the json array using foreach controller. Now here is the issue, when I log.info(json), I get the same data very time but there are other data as well which can only be seen in treeview.

I dont understand that how do I access all the data.