Forum Discussion

picengr's avatar
13 years ago

Groovy Script getXMLFolder does not work in another testcase

So I have one testcase called ScriptFolder under which I have GetAuth testStep which gets an authToken. I have a script called "Groovy Script" which gets the authToken from GetAuth testStep and use it in Subsequest request for example, getting order query.

def proj = testRunner.testCase.testSuite.project ;
def tcase = proj.testSuites["API_testSuite"].testCases["ScriptFolder"] ;
def teststep = tcase.getTestStepByName("GetAuth");
testRunner.runTestStepByName("GetAuth")
def propValue = teststep.getPropertyValue("Response");
def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context)
def holder = groovyUtils.getXmlHolder(propValue)
def authTokenfromLogin= holder.getNodeValue("//@authToken")

now iterating all testcases and updating the authToken in different testcases

for( testCase in testRunner.testCase.testSuite.getTestCaseList() ) {
log.info "Starting testcase "+testCase.getName()
for (step in testCase.getTestStepList() ){
def abc = step.getName()
if (abc != "GetAuth" && step.hasProperty("Request")){
if (req!=""){
def holder1 = groovyUtils.getXmlHolder(abc+"#Request")
holder1.getNodeValue("//@authToken")
holder1["//@authToken"]=authTokenfromLogin
log.info authTokenfromLogin
holder1.updateProperty()
}
}
}
}

I am running this from "ScriptFolder" testcase. It fails when it tries to set the authToken on another testcase. It fails at,
"def holder1 = groovyUtils.getXmlHolder(abc+"#Request")"

It gives Unexpected element CDATA error.


However, if I clone the groovy script to other testcase and run it, it does not give the CDATA error and sets the authToken fine on local testcase.

What am I doing wrong? Or running a script from another testcase is not supported in SOAPUi?
No RepliesBe the first to reply