cancel
Showing results for 
Search instead for 
Did you mean: 

Using testSuite setup script to modify testStep request inputs - getXmlHolder CDATA error

Highlighted
Member

Using testSuite setup script to modify testStep request inputs - getXmlHolder CDATA error

Hi All,

I have a test suite which contains two test cases, each with multiple steps.

I would like to be able to run the suite whilst reading input values for the step requests from an external data source, so that during execution of the test suite, the request of each test step is automatically updated as per changes made to the external data source.

 

I have been able to do this by writing a test case setup script, which loops through its steps and updates their request values:

    // Get list of test steps
def tCase = testRunner.testCase
def tSteps = tCase.testStepList    

    // Iterate through each test step
for(step in tSteps){

            // Save the input of the test step to a variable called "holder"
        def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context )
        holder = groovyUtils.getXmlHolder(step.name+"#Request")

            // Change value of the input node to the desired input value
        holder[inputNode] = "inputValue"
            
            // Overwrite step request with updated values saved in "holder"
        holder.updateProperty()
    }

This worked fine and when I run the test suite, each test case updates its own steps' requests before running them.

I plan to add many test cases in the future, and instead of adding the setup script to every test case, I would like to modify it to run at the test suite level so it will apply to any test case which may be added in the future.

 

I modified the script for test suite level as follows:

	// Get list of test cases in current test suite	
def tCase = testSuite.testCaseList

	// Iterate through each test case in the test suite
for (cases in tCase){
	
		// Get list of test steps in current test case
	def tSteps = cases.testStepList	

	for(step in tSteps){
		
			def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context)
			holder = groovyUtils.getXmlHolder(step.name+"#Request")
			
			holder[inputNode] = "inputValue"
			holder.updateProperty()

However, when I try to run this, I get the following error:

"org.apache.xmlbeans.XmlException: error: Unexpected element: CDATA"

 

I have attached the error log, but the two lines which appear to show the issue are:

"at com.eviware.soapui.support.GroovyUtils$getXmlHolder.call(Unknown Source)"

and

"Caused by: org.xml.sax.SAXParseException; systemId: file:; lineNumber: 1; columnNumber: 1; Unexpected element: CDATA"

 

If I comment out the "holder" lines, the script executes and all the test steps/cases run, only they do not update their request values.

 

From this and testing a variety of changes, the issue appears to be the value of "context" at test suite level.

 

At every point in the test suite script, log.info(context) gives me:

{ThreadIndex=0, RunCount=0}

 

However, when running the script as a test case setup script, the value of context is:

{ThreadIndex=0, RunCount=0, Interactive=true, #HTTP_STATE=null, loopButton=javax.swing.JToggleButton[,45,3,22x21,alignmentX=0.0,alignmentY=0.5,border=javax.swing.border.CompoundBorder@1c076a8,flags=16777504,maximumSize=,minimumSize=,preferredSize=java.awt.Dimension[width=22,height=21],defaultIcon=jar:file:/C:/Program%20Files%20(x86)/SoapUI-5.4.0/bin/soapui-5.4.0.jar!/com/eviware/soapui/resources/images/loop.png,disabledIcon=,disabledSelectedIcon=,margin=javax.swing.plaf.InsetsUIResource[top=0,left=4,bottom=1,right=4],paintBorder=true,paintFocus=true,pressedIcon=,rolloverEnabled=true,rolloverIcon=,rolloverSelectedIcon=,selectedIcon=,text=]}

 

I noticed that the testCase setup script is invoked with testRunner as a variable, but testSuite setup script is invoked with runner variable, but I do not know if this makes a difference.

 

I have tried using various property expansions, but at the end there always appears to be nothing in "context". At this moment I am completely stumped as to what to try next.

 

Any help or advice with this issue (or in general) would be greatly appreciated.

Thanks,

speedy

0 REPLIES 0
New Here?
Join us and watch the welcome video:
Announcements
Top Kudoed Authors