Forum Discussion

ErikG's avatar
ErikG
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:

<soapenv:Body>
         <ns:QueueResultsRequest>
         <!--Optional:-->
         <ns:OrganizationId>${#TestSuite#OrganizationID}</ns:OrganizationId>

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

                     <arr:guid>255BB69A-3471-4145-B9A9-551732F85BB6</arr:guid>
                     <arr:guid>17957A99-DE0C-4320-913C-54A4AD9D227F</arr:guid>

         </ns:ResultIds>
         <!--Optional:--> 
         <ns:TestName>Hoofstuk 5</ns:TestName>
        </ns:QueueResultsRequest>
</soapenv:Body>

  • Radford's avatar
    Radford
    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
    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 XmlParserNode, and QName objects. 

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