2
votes

I'm extracting 2 two set of values in two different lists from a JSON response using JSON extractor

Extractor1

enter image description here

I'm looping through values of list1 using a foreach loop, so i can easily get values from list1 one-by-one:

enter image description here

But I want to send values from list2 in one of the request inside this foreach loop. How can I get values from list2 one-by-one so that I send it as a parameter:

enter image description here

This HTTP request will be called for each item in list. I want to add value from list2 to lastUpdated parameter in given HTTP request.How can I do it?

I did some research and got to know that we can use Beanshell PreProcessor for this task. I added following code in Beanshell PreProcessor:

idx = Integer.parseInt(vars.get("item_no"))-1;
vars.put("date", vars.get("list2")[idx]);

And tried passing date as follows:

{"qId":"${q_oid}","items":[{"itemId":"${qi_id}","lastUpdated":"${date}"}]}

But I'm getting blank in the lastUpdated arg. Note : I have added 'date' in the user defined variables of the test plan

1

1 Answers

2
votes

list2 variable are saved as: list_1 list_2 list_3,...

So change the variable name inside ForEach Controller

vars.put("date", vars.get("list2_" + idx));

So for example when the input variable has the name inputVar, the following variables should have been defined:

inputVar_1 = wendy inputVar_2 = charles inputVar_3 = peter inputVar_4 = john

Notice also JMeter holds special variable inside ForEach Controller:

JMeter will expose the looping index as a variable named jm__idx. So for example, if your Loop Controller is named FEC, then you can access the looping index through ${__jm__FEC__idx}. Index starts at 0