Forum Discussion

xworker's avatar
xworker
Occasional Contributor
12 years ago

how to access requests in other testCases/testSuites

Hi
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. This script works as long as the script is in the same TestCase as the request it is trying to access. How to do this for other TestCases and other TestSuites?

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

def project = context.testCase.testSuite.project

def testSuite = project.getTestSuiteAt(5)

def testCase = testSuite.getTestCaseAt(0)

def testStep = testCase.getTestStepAt(0)


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



Thx
  • xworker's avatar
    xworker
    Occasional Contributor
    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()