Forum Discussion

jg0888's avatar
jg0888
Contributor
7 years ago

Use Datasink to pull mutliple nodes with the same name.

Hey everyone,

 

I am using a DataDriven test to input employee User ID's and Company ID's into a request and then trying to pull the following XML nodes of entityType and entityID with DataSink to create a report.

 

Is there a way to pull all of the "entityType" and corresponding "entityId" when the number of "entityAccess" nodes changes depending on the User ID and Company ID used?

 

So far, I can only pull them if I use the Xpath to pull a specific entity type:

 

${EmployeeEntityAccess - Conv#Response#declare namespace ns1='http://fwdco.com/api'; //ns1:getEntityAccessResponse[1]/ns1:return[1]/ns1:entityAccess[1]/ns1:entityType[1]}

 

Here is a sample XML response:

 

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<getEntityAccessResponse xmlns="http://fwdco.com/api">
<return>
<errorCode>0</errorCode>
<errorMessage/>
<entityAccess>
<entityType>Department</entityType>
<entityId>167SCL</entityId>
</entityAccess>
<entityAccess>
<entityType>Department</entityType>
<entityId>168PHE</entityId>
</entityAccess>
<entityAccess>
<entityType>Location</entityType>
<entityId>1</entityId>
</entityAccess>
<entityAccess>
<entityType>Location</entityType>
<entityId>2</entityId>
</entityAccess>
<entityAccess>
<entityType>WorkGroup</entityType>
<entityId>DTLV18</entityId>
</entityAccess>
</return>
</getEntityAccessResponse>
</soap:Body>
</soap:Envelope>

  • It looks like you have two DataSource steps, one for each entityId and entityType? This is not necessary. You should have one XML DataSource that can provide both. That might be causing the issue you are seeing.

  • Nastya_Khovrina

    From the above response, is there a way to pull all of the corresponding "entityType" and "entityId" using DataSink into a report without specifying the number of "entityAccess" nodes?

     

    Basically I want to see if I can automatically add this table which I can view when I click "entity Access" in the Outline view. See attached screenshot.

     

     

    • groovyguy's avatar
      groovyguy
      Community Hero

      I am going to assume the number of records that get returned are an unknown dynamic quantity. Or rather, the number returned are not always going to be the same.

       

      If that is the case, the only way to dynamically handle this that I am aware of is to use a groovy script to figure out how many values are returned and to store them as needed in a file.

       

      If you do know the number that are going to be returned and it is the same every time, you could still utilize groovy script to populate the properties and XPATH statements in the data sink. 

       

      Either way that I can think of still relies on working knowledge of groovy script. 

  • groovyguy - Your assumption is correct in that the number of records is not always the same.

     

    I do recognize the ability to get a specific number or records from specific nodes using XPath statements, but I was hoping for an easier way. Unfortunately, I do not have much knowledge when it comes to groovy. Thanks for your help though!

    • groovyguy's avatar
      groovyguy
      Community Hero

      jg0888: It's been awhile since I've worked with a Data Sink and a file, so I am not 100% certain, but I believe it appends data to the file instead of overwriting it each time. If that's the case, uou might be able to set up a DataSource and DataSource Loop to achieve the desired results.

       

      With an XML DataSource, you can set up an Xpath statement that'll select the elements required, and using the loop would parse through all of the available objects. This is how I think it could work laid out in test step order:

       

      1. Request whose response has the needed data
      2. XML DataSource with XPATH selecting the data above
      3. Data Sink writing data using the DataSource properties to a file
      4. Data Source Loop that uses the DataSource and loops back to the Data Sink.

       

      This may take a little bit of trial and error, but it'll dynamically store the records from the response via the XML Data Source loop. No groovy required at this point.

      • jg0888's avatar
        jg0888
        Contributor

        groovyguy - Thanks for the suggestion. I was able to create a DataSource from the get XML response, and then pull information from there. This proved to be a lot easier than pulling directly from the Soap Request test step.

         

        However, I am seeing that it is skipping every other value although my DataSourceLoop test step iteration is set to only 1. It looks to be every other from what I can tell which is very confusing. Also, it skips depending on which DataSource step is chosen.

         

        Any idea why this would happen? I can add any additional screenshots or information that you might deem helpful from my source. Attached what my SoapUI Pro Test Steps look like.