'I want to put all the items of that were taken from a get api request in list format in Jmeter
I have a get api and I want to get all the ID's that are present in it and put them in a list/array so I can use it in other api where I want to seperate even and odd elements from that list and pass it as a variables
The get api is something like https://api.abs.com/contents
From this api I have taken the ID's using json extractor and stored them in id variable name.
Now I want to put all id elements into a list/array and seprate them into odd and even number and store in 2 variables(if possible provide the code how to seprate them as well)so I can pass them into a post api in loop
How is this possible Is there any way in Jmeter to do this..please help me out
Solution 1:[1]
To do any sort of logic in JMeter, it's usually best to use a scripting sampler or pre/post-processor to implement a script with the logic. If you use a JSR223_Sampler, you can import or run a Groovy script.
For example your Groovy code to get the even or odd values and store them in a JMeter variable might look something like this:
// Get JMeter variables
def allValues = vars.get("valuesVariable")
def values = allValues.split(",")
// Apply groovy logic
def evenValues = values.findAll({ i -> (i as int) % 2 == 0 })
def oddValues = values.findAll({ i -> (i as int) % 2 != 0 })
// Save as JMeter variables
vars.put("evenVariable", evenValues)
vars.put("oddVariable", oddValues )
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 |