Forum Discussion

dinojadhav's avatar
dinojadhav
Occasional Contributor
5 years ago
Solved

Groovy script query

I have a groovy script to capture a log and the same is working fine means the logs capture properly however if run the groovy only then getting "org.apache.xmlbeans.xmlexception.error.unexpected element.CDATA error at line 57."

 

Below is my code :

 

import com.eviware.soapui.support.GroovyUtils
import com.eviware.soapui.support.XmlHolder
import jxl.*;
import jxl.write.*
import org.apache.commons.lang.StringUtils

def Time = new Date().format("dd-MMM-yyyy h_mm_ss a")
def directory = testRunner.testCase.testSuite.project.getPropertyValue("Logs")
File fold = new File (directory)
fold.mkdir ()

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

//Project Name:
def ProjectName=testRunner.testCase.testSuite.project.name

//TestSuite Name:
def TestSuiteName=testRunner.testCase.testSuite.name

//Test Case Name:
def TestCaseName=testRunner.getTestCase().getName()

//Creating File
def responseFile = new File (directory,TestCaseName+"_${Time}"+".doc")

def TestCaseDescription = testRunner.testCase.getDescription()
responseFile.append ("Project Name :${ProjectName}\n\n")
responseFile.append ("TestSuite Name :${TestSuiteName}\n\n")
responseFile.append ("TestSuite Name :${TestCaseName}\n\n")

//def testCaseCount = testRunner.testCase.testSuites[TestSuiteName].getTestCaseCount()

def count = testRunner.testCase.getTestStepCount()

for (i=1;i<count;i++){

def StepName = testRunner.testCase.getTestStepAt(i).getName()

if (StepName.toString()== "Property Transfer" ||
StepName.toString()== "Delay" ||
StepName.toString()== "GetLineiatta" ||
StepName.toString()== "Generate Log file"||
StepName.toString()== "FlightNo"||
StepName.toString()== "LINEIATTA"||
StepName.toString()== "GetReservation"||
//StepName.toString()== "GetReservation"||
StepName.toString()== "Capture Values from GetRes"||
//StepName.toString()== "ChangePartition"||
StepName.toString()== "Partition Property"||
//StepName.toString()== "Display Airline PNR"||
StepName.toString()== "PNR*")


log.info StepName

else{
def RQHolder = groovyUtils.getXmlHolder(StepName.toString()+"#Request")
RQHolder.namespaces["xmlns"] = "http://webservices.sabre.com/sabreXML/2003/07"
def nodeRQ = RQHolder.getNodeValue("//xmlns:SabreCommandLLSRQ/xmlns:Request/xmlns:HostCommand")

def RSholder = groovyUtils.getXmlHolder(StepName.toString()+"#Response")
RSholder.namespaces["xmlns"] = "http://webservices.sabre.com/sabreXML/2003/07"
def nodeRS = RSholder.getNodeValue("//xmlns:SabreCommandLLSRS/xmlns:Response")

def Name = testRunner.testCase.testSuite.getName()
responseFile.append (context.expand(StepName.toString()+ " : ${nodeRQ}\n"))
responseFile.append (context.expand(StepName.toString()+ " : ${nodeRS}\n\n"))
}
}

  • dinojadhav's avatar
    dinojadhav
    5 years ago

    Hallo All,

     

    Got solution for this issue. The problem persists in my groovy scripts If statement. I am passing a lot of unnecessary step names in If statement and those step names are already identified by groovy because of which the CDATA error is occurring. I have removed the unwanted step names from if statement and re-run the script and the same is working fine.

     

    Example Elaborated : 

     

    in my test case below are the steps : 

    1. Click Login

    2. enter user name

    3. enter password

    4. Delay (Wait)

    5. click on submit

    To capture log of all these steps I have the above given groovy script and in that, I have added If condition to capture the step names. Groovy script is able to understand the normal soapui steps but if we have "Delay, Property Transfer, Run testcase" etc then soap is unable to capture the steps hence the If condition is written to capture these steps and in that If condition added few step names which are not there and due to which the CDATA error is occurring.

     

6 Replies

  • nmrao's avatar
    nmrao
    Champion Level 3
    Difficult to comment without respective data.
    • dinojadhav's avatar
      dinojadhav
      Occasional Contributor

      Hi Rao,

      Which kind of data you need.

       

      Thanks,

      Dinesh

      • nmrao's avatar
        nmrao
        Champion Level 3
        To validate the xpath you were using are correct.