Forum Discussion

ario's avatar
ario
New Contributor
8 years ago
Solved

Load records from Datasource[Excel] into SOAP Request as multiple XML nodes

Hi,

 

So I have an excel file with 2 rows of person names.

 

person_name
John Smith
Linda Howard

I have loaded the excel file into DataSource, but then

 

I wanted to load the result into the SOAP Request so the SOAP request will be like this:

 

<xml>
<names>
<name>
<person>John Smith</person>
</name>
<name>
<person>Linda Howard</person>
</name>
</names>
</xml>

How can I do that?

I'm new to SOAP UI and not familiar with Groovy Script :(

 

 

Can you please help?

 

 

Thanks,

Ario

5 Replies

  • Radford's avatar
    Radford
    Super Contributor

    There are a few ways, and you shouldn't need to resort to Groovy Script. Two of the simple built in methods are:

     

    1. Use the Point and Click Get Data functionality from within your SOAP request to reference the Data Source properties.
    2. Put a Property Transfer test step between your two test steps and configure appropriate to your needs to transfer your data.

     

     

     

     

    • ario's avatar
      ario
      New Contributor

      Hi,

       

      Thank you for your reply, I think your solution will work if only the XML already had 2 nodes. Please correct me if I'm wrong?

       

      Sorry for being not clear, so my question is how to create a dynamic nodes the XML based on the datasource[excel] records?

       

      So, in the excel I've got:

      person_name
      John Smith
      Linda Howard
      Joe Bloggs

      My current SOAP UI XML is below:

      <xml>
      <persons>
      <person>
      </person>
      </persons>
      </xml>

      I wanted the end result to look like below:

      <xml>
      <persons>
      <person>John Smith</person>
      <person>Linda Howard</person>
      <person>Joe Bloggs</person>
      </persons>
      </xml>

       

       

      Then finally to trigger the 'updated' XML request

      • Radford's avatar
        Radford
        Super Contributor

        OK so I think I know what you want, assuming that it's not always going to be three records (because if it was you could just pre-create the nodes in your request). I think you might need groovy script.

         

        (As a side note, you shouldn't need to loop in groovy, the DataSource step can be paired with a DataSource Loop test step to take care of the looping, check out the pages on Data Driven Testing)

         

        You can still use the point and click get data functionality from within a groovy script, so this takes care of getting data into your script. Are you wanting to get more that one record from your datasource per loop? If so check out this page.

         

        You then need to get your XML from the SOAP request, manipulate the XML, I like to use the Groovy

        XmlParser to do this. then update your SOAP request with the new details.

         

        The pseudo code will look a bit like this:

         

        import groovy.xml.*
        import groovy.util.XmlParser
        import com.eviware.soapui.support.GroovyUtils
        
        // Get SOAP request test string
        def request = context.expand( '${SOAP Request#Request#RootNode}' )
        
        // Parse request string into Node object
        // NB: This is non-namespace-aware 
        def parser = new XmlParser()
        def rootNode = parser.parseText(request)
        
        // Manipulate rootNode object here
        
        // Update SOAP request with new data.
        def groovyUtils = new GroovyUtils(context)
        groovyUtils.setPropertyValue('SOAP Request', 'Request', XmlUtil.serialize(rootNode)) 

         

         

        As mentioned the above code is not XML namespace aware, if you need this check out the XmlParser JavaDoc (In fact this is worth looking at regardless)

         

  • ario's avatar
    ario
    New Contributor

    Hi,

     

    So I've got 3 rows in datasource[excel] column A:

    book_name
    book1
    book2
    book3

    How do i read them in groovy script?

     

    So that I can do loop in groovy..

     

    Please let me know

     

    Thanks,

    Ario