Forum Discussion

jbuttimer's avatar
jbuttimer
Contributor
9 years ago

Having trouble looping and writing the result (Serial Number) to the Global Preferences

I've tried a Groovy script. It loops the correct number of times, 5, however it loops twice on the last loop, causing the step to fail.

 

I've tried Data Source loop but it only loops one time.

 

First I used a DataSource selecting a Groovy as the source.

The Properties are SerialNumber. Using Groovy as a DataSource I don't see any way to define how many times to loop.

 

I would appreciate any help. I've made a mess of this! Any suggestions on how I should approach this?

 

def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context )  
//def row = testRunner.testCase.testSteps["DataSource"].currentRow
//Thread.sleep(4000)
// get XmlHolder for request message def
// The format for this in your own script is holder = groovyUtils.getXmlHolder( "YourStepNameGoesHere#Request" )
holder = groovyUtils.getXmlHolder( "AddTransactionForSerial#Request" )

// add new data using XPath
// The format for this in your own script is
// holder["//YourXMLlocation"] = whatever it is you want to write in the XML
// FYI in my request XML there is no data in the field I'm writing to
SerialNumber = System.currentTimeMillis()
holder["//brig:SerialNumber"] = SerialNumber

// write updated request back to teststep
holder.updateProperty()


def SerialNumberForSerialized = context.expand(holder["//brig:SerialNumber"])
//com.eviware.soapui.model.propertyexpansion.PropertyExpansionUtils.globalProperties.setPropertyValue('SerialNumberForSerialized'+i, SerialNumberForSerialized)
com.eviware.soapui.SoapUI.globalProperties.setPropertyValue( 'SN'+SerialNumberForSerialized, SerialNumberForSerialized);   //- See more at: http://techknowdips.blogspot.com/2012/11/groovy-scripting-turn-soap-ui-into.html#sthash.Jp9CfdBy.dpuf
//testRunner.runTestStepByName("AddTransactionForSerial")
//holder["//brig:SerialNumber"] = ''
//Show the XML when you run the script manually
context.requestContent = holder.xml

 

 

No RepliesBe the first to reply