-
Notifications
You must be signed in to change notification settings - Fork 2
Parsing_JSON_Extract_Object_Pass_To_Body_of_Another_Request_Body
Rajendra Prasad Reddy Penumalli edited this page Apr 17, 2020
·
1 revision
- Send a request using HTTP Sample
- Attach Post Processor
- Use JSR-223 Processor Element
import groovy.json.*
def jsonResponse=prev.getResponseDataAsString()
def jsonSlurper = new JsonSlurper()
def obj = jsonSlurper.parseText(jsonResponse)
def totalRecords=obj.size();
log.info "----totalRecords: $totalRecords"
def index=0;
def objList=[]
obj.each{
objList.add(obj)
}
def objListCount=objList.size()
//Generate a Random number between 0 to Maxcount Of obj list
def minListIndex=0
def maxListIndex=objectsCount-1
def randomObjListIndex = new Random().nextInt(maxListIndex+1)
def randomObject=numberList[randomListIndex]
vars.putObject("obj",objList[0]);
vars.put("objNumber",randomListIndex.toString());
### Use If Controller
${__javaScript(parseInt(vars.get("objCountToUpdate"))>1)}
${__groovy((vars.get("objCountToUpdate")).toInteger()>0)}