Forum Discussion

ErikG's avatar
New Contributor
8 years ago

How to transfer/add a property to an array in the next soapcall

As a precondition I have a soap call in a datasource loop wich posts student-results into a database. The response provides the guid of the resultentry.

The soap call under test posts the resultid's (in an array) to retrieve all the student-results.


Question: How can I transfer (or better: add) the resultids to the array of this soap request. 


(the property transfer I tried can only add/replace 1 entry)

The call looks like this:


                     <!--Zero or more repetitions:-->


         <ns:TestName>Hoofstuk 5</ns:TestName>

2 Replies

  • Radford's avatar
    Super 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
    def request = context.expand( 'Reference To Your Soap Request' )
    // Define required namespaces as our paser will be namespace aware
    def soapenv = new Namespace('', '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 XmlParserNode, and QName objects. 

    • ErikG's avatar
      New 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.