Andreas Blomqvist
Andreas Blomqvist

Reputation: 437

Dynamically setting input in SOAPUI requests with Groovy

I want to write a groovy script that sets input in requests. It works fine when the groovy is executed within the same testsuite, but I want this script the go thru several testsuites. This is my code, for testing I am getting the 5th testsuite, the first testcase and the first teststep. It is the getXmlHolder line the fails with "Unexpected CDATA" error. I have tried to add the testSuite and testCase to the inputHolder string but that doesn't help either.

def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context ) 

def project = context.testCase.testSuite.project

    def testSuite = project.getTestSuiteAt(5)
    log.info(testSuite.getLabel())
    def testCase = testSuite.getTestCaseAt(0)
    log.info(testCase.getLabel())
    def testStep = testCase.getTestStepAt(0)
    log.info(testStep.getLabel())

    def teststepname = testCase.getTestStepAt(0).getName().toString() 
    def inputHolder = +teststepname + "#Request"
    log.info(inputHolder);
    def holderRawReq = groovyUtils.getXmlHolder(inputHolder)
    holderRawReq["//tem:brandId"] = "test"

I think the getXmlHolder only checks in the testSuite it resides in, so the question is how to make it access other testSuites?

Upvotes: 0

Views: 10282

Answers (1)

Andreas Blomqvist
Andreas Blomqvist

Reputation: 437

Ok, solved it.

You have to create a context for the testStep where you currently are, like this:

import com.eviware.soapui.impl.wsdl.teststeps.*

def project = context.testCase.testSuite.project
def testSuite = project.getTestSuiteAt(5)
def testCase = testSuite.getTestCaseAt(1)
def testStep = testCase.getTestStepAt(1)

// this will get the current teststep name
def teststepname = testStep.getName().toString() 

//create a context for the teststep where we are
def testStepContext = new com.eviware.soapui.impl.wsdl.testcase.WsdlTestRunContext(testStep);

//create a util on the testStepContext
def groovyUtils = new com.eviware.soapui.support.GroovyUtils( testStepContext ) 

def inputHolder = teststepname + "#Request"
def holderRawReq = groovyUtils.getXmlHolder(inputHolder)

holderRawReq["//tem:brandId"] = "test7"
holderRawReq.updateProperty()

Upvotes: 3

Related Questions