richie
7 years agoCommunity Hero
Passing a json node (rather than the node's value) to a Property
Hi, I need to grab a node name rather than the value from a .json request and pass it onto a subsequent .json request's body. I have 2 api's I need to test. 1 is a POST followed by a GET....
- 7 years ago
richie, here is one more method to execute a REST step for multiple UIDs. In this example I have used your response with 3 different UIDs.
I saved below response in a text file and reading it from there.
{ "$id" : "1", "1826d9a8-f542-e811-8120-5065f38b0571" : { "$id" : "2", "StatusCode" : 0, "Outcome" : "NewCall" }, "beb19fbb-f542-e811-8120-5065f38b0571" : { "$id" : "3", "StatusCode" : 0, "Outcome" : "NewCall" }, "ffe022cc-f542-e811-8120-5065f38b0571" : { "$id" : "4", "StatusCode" : 0, "Outcome" : "NewCall" } }
groovy script to extract GUIDs and iterate through them and execute RestTestStep for each GUID.
import groovy.json.JsonSlurper def response = new File("c://users//XXXX//desktop//response.txt").text def json = new JsonSlurper().parseText response def i = 0 def UID = [] json.each{ if(it.key !='$id'){ UID += it.key } i++ } log.info UID //## Array with 3 unique IDs ##// def j=0 def uniqueId UID.each{ //##Update TestCase Property with UID ##// uniqueId = UID[j] testRunner.testCase.setPropertyValue("uniqueId", UID[j]) //store in a testcase property and then use this in subsequesnt RestTestStep// log.info "Executing RestStep for UID- $uniqueId" testRunner.runTestStepByName("YourRESTTestStep") // Execute RestStep Here // j++ }