0
votes

I have used While controller in Jmeter and fetching the data (i.e JSON _id values) one by one from the Response. total there are 50 Id's/per response.

  1. E.g. "_id: "57565556654","_id":"68676665555", "_id": "87686877545"

Http Request - When this request is submitted I am getting _id from the response. Used JSON extractor to fetch the _id's from the Response. i.e. 50 ids. Ref Name = DeleteQuestionsID

In Debug Sampler DeleteQuestionsID_MatchNr shows DeleteQuestionsID_MatchNr =1, bcoz JSOn extarctor is running inside While loop

I need to Pass these 50 Id's one by one to Next Http request which is outside the While loop.

Http Request : `'/v1/tests/'$'{TestID}/questions/${DeleteQuestionsID}

`How to achieve this?

2

2 Answers

0
votes

You can save the values into JMeter Variables by adding JSR223 PostProcessor after the JSON Extractor and using the following code:

vars.put('DeleteQuestionsID_' + vars.get('__jm__While Controller__idx'), vars.get('DeleteQuestionsID'))

It will generate 50 JMeter Variables like:

DeleteQuestionsID_0=foo
DeleteQuestionsID_1=bar
DeleteQuestionsID_2=baz
etc.

which can re-use later on where required.

vars is a shorhand for JMeterVariables class instance, it provides read/write access to all JMeter Variables in scope, check out Top 8 JMeter Java Classes You Should Be Using with Groovy for more information on this and other JMeter API shorthands available for JSR223 Test Elements.

0
votes

This is why ForEach_Controller created for

ForEach controller loops through the values of a set of related variables. When you add samplers (or controllers) to a ForEach controller, every sample (or controller) is executed one or more times, where during every loop the variable has a new value. The input should consist of several variables, each extended with an underscore and a number. Each such variable must have a value. So for example when the input variable has the name inputVar, the following variables should have been defined:

inputVar_1 = wendy
inputVar_2 = charles