So i have a bit tricky ( for me at least ) situation. I have list of 100 users and need to get some address information from each of 100 users. Unfortunately our REST API is not allowing to obtain this information via one GET request, rather i need to call 100 GET requests ( one GET request in a loop ) and to pass the ids of 100 users in order to get information about address.
So the question is: How would i use JSON Extractor value ( to get address field value from response ) and put it in array and to repeat this process for all 100 users. And to later use that array to obtain information about size of array and to check if certain element of that array contains certain data?
Given you have groovy tag I'll provide solution with Groovy.
def addresses = vars.getObject('addresses') ?: []
- get array of addresses from JMeter Variables or return an empty array if the variable is null (first execution)def address = new com.jayway.jsonpath.JsonPath().read(prev.getResponseDataAsString(), '$.your-json-path-expression-here')
- extract address from the previous sampler response using JsonPathaddresses.add(address)
- add the address to addresses
arrayvars.putObject('addresses', addresses)
- store the array into JMeter Variablesdef size = addresses.size()
- get the array sizedef containsData = addresses[5].contains('the data you are looking for')
- checks if 6th address contains some dataMore information on these vars
, prev
and other shorthands: Top 8 JMeter Java Classes You Should Be Using with Groovy