0
votes

Jmeter - I have multiple values ( 250 values approx as a minimum ) returned from a Get Request in the form of array in json format , i need pass each of the value in the array as a parameter in next GET request

Request 1

> Get http://xxx/store1?

Response in json format looks like this

{"store1":"peirre","inventorylist":["item1","item2","item3"..........."item250"]}

I will need to use each one of item in next GET request like this to get is feautures like price , available quantity,production site etc.,

Request 2

Get https://xxx/store1/item1?
Get https://xxx/store1/item2?
Get https://xxx/store1/item3?

It would be easy when i can read the response and write each value in the array to CSV file so that my next get request would simply read the CSV file and fire all the requests

Is there a way to achieve this ???

Thank you in advance

2
No need to save CSV file. You can use JSON Extractor to create an array containing item1...itemN, then put an HTTP Request in a Loop Controller and supply values from the array.marekful

2 Answers

1
votes
  1. Add JSON Extractor as a child of the request which returns the above JSON
  2. Configure it as follows:

    • Names of created variables: anything meaningful, i.e. item
    • JSON Path Expressions: $.inventorylist.*
    • Match No.: -1
  3. Add ForEach Controller after the first HTTP Request sampler and configure it as follows:

    • Input variable prefix: whatever you used as "Names of created variables" in the JSON Extractor, i.e. item
    • Output variable name: anything meaningful, i.e. current_item
  4. Add HTTP Request sampler as a child of the ForEach Controller and use https://xxx/store1/${current_item} in "Path" field - it will iterate through all the "item"s

    JMeter JSON Extractor and ForEach Controller

1
votes
  1. Add a Json Extarctor to the first Get Request with the following properties enter image description here

2.Add a JSR223 post processor and initialize a counter as shown below enter image description here

  1. Add a while controller and place your get request in while controller.

add the following condition

${__javaScript(parseInt(vars.get("counter"))<=parseInt(vars.get("List_matchNr")))}

as shown below

enter image description here

  1. To your second get request add a JSR223 post processor and increment the counter as shown below

    int counter = Integer.parseInt(vars.get("counter")) +1;

    vars.put("counter",Integer.toString(counter));

enter image description here

  1. Use ${__V(List_${counter})} to replace hardcoded value

This loop will run through the match number and sends a request with each item to server

enter image description here

For more information on while loop please follow the link