Forum Discussion
This is EventHandler script.
Groovy Step script is:
import com.eviware.soapui.support.XmlHolder
import net.sf.*
import net.sf.json.*
import net.sf.json.groovy.*
import groovy.json.JsonSlurper
import groovy.json.JsonBuilder
//## Get test step name //
def currentStepInd = context.currentStepIndex
def testStep = testRunner.testCase.getTestStepAt(currentStepInd).name
def TestStepName = testRunner.testCase.getTestStepAt(currentStepInd - 1).name
def RESTTestStep = testRunner.testCase.getTestStepAt(currentStepInd + 1).name
log.info "Running $testStep..."
log.info "------------------------------------------------"
log.info "Collect TestData from Testsuite Properties..."
def USER = context.expand('${#TestSuite#USER}')
//Parse JSON response
log.info "Parsing JSON response from $TestStepName..."
def SECNO = []
def JsonPayload
def i = 0
def response = context.expand('${'+TestStepName+'#Response}')
def json = new JsonSlurper().parseText response
json.each{
SECNO += it.SecurityNumber
JsonPayload = it
i++
}
//##Update JSON Nodes ##//
def j = 0
def jsonbuilder = new JsonBuilder(JsonPayload)
SECNO.each{
//Update JSON nodes//
jsonbuilder.content.SecurityNumber = SECNO[j]
jsonbuilder.content.UpdatedByUser = USER
//##Update TestCase Property to contain parsed json ##//
testRunner.testCase.setPropertyValue("SECNO", SECNO[j])
testRunner.testCase.setPropertyValue("JSONPayload", "${jsonbuilder}")
log.info "Updating JSON payload to TestCase property: JSONPayload"
log.info "JSON Payload is : " + context.expand('${#TestCase#JSONPayload}')
log.info "------------------------------------------------"
log.info "------------------------------------------------"
testRunner.runTestStepByName(RESTTestStep) // Execute RestStep Here //
j++
}
log.info "Finished $testStep..."
log.info "------------------------------------------------"
- nmrao7 years agoChampion Level 3This is lot of code, can you precisely explain what it is intended to do?