Forum Discussion
Radford
8 years agoSuper Contributor
I'm not sure if this is the best way, but I have done what you are trying to do with a Groovy TestStep using the Groovy XmlParser, though this was slightly complicated by the fact that the XML has namespaces.
I've tried to match the code to your example, so it's not tested and might need to be tweaked a bit (I've also assumed that Request body will be wrapped with an envelope element, again if not adjust as needed).
import groovy.xml.* import groovy.util.XmlParser import com.eviware.soapui.support.GroovyUtils def request = context.expand( 'Reference To Your Soap Request' ) // Define required namespaces as our paser will be namespace aware def soapenv = new Namespace('http://schemas.xmlsoap.org/soap/envelope/', 'soapenv') def ns = new Namespace('http://yourfirstnamespace', 'ns') def arr = new Namespace('http://yoursecondnamespace', 'arr') // Parse the namespace aware XML SOAP Request def parser = new XmlParser(false, true) def envelope = parser.parseText(request) // Obtain the node we want to append too. def resultIds = envelope[soapenv.Body][0][ns.ResultIds][0] // Create and Append the new node def guidQName new QName('http://yournamespace', 'guid', 'arr') resultIds.appendNode(guidQName, 'GUID Value here') // Update actual test step with new request data def groovyUtils = new GroovyUtils(context) groovyUtils.setPropertyValue('SOAP Test Staep Name', 'Request', XmlUtil.serialize(envelope))
Here are the links for the JavaDocs for the XmlParser, Node, and QName objects.
- ErikG8 years agoNew Contributor
Thank you for putting me in the right direction, I was kind of afraid it would lead to Groovy. I'll be working your example out, seems clear enough. I'll let you know how it worked out. Cheers.
Related Content
- 4 years ago
Recent Discussions
- 15 years ago