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 "------------------------------------------------"
- New2API7 years agoFrequent Contributor
I thought my original question/post did explain that.
Here is what I am doing:
Eventhandler script - Runs after a step (actually any step). But code looks for 'restrequest' to execute big block of code. Purpose of this code is to collect stats from the rest request and record in database result table.
TestCase structure:
1. REST step 1 (Get some response)
2. Groovy Step
3. REST step 2 (Post data sent in jsonpayload)
Groovy step's purpose:
- Collect the response from REST Step 1
- Collect unique Nos (SECNO) from the response and store in an array
- Iterate to build JSONpayload and replace SECNO in the jsonpayload during each iteration
- Run REST step 2 with each iteration, so that json payload has unique SECNO each time
Assumption:
Eventhanlder would run after each step and when a 'REST' step is executed via groovy step, 'Big block of code' inside eventhandler would run since a REST test step was executed.
Issue:
'Big block of Code' in event handler is not executed after REST Step 2 is successfully executed via groovy step.