Forum Discussion

arshwarsi's avatar
arshwarsi
New Contributor
13 years ago

Heirarchical DataSource Parameterize Array Element Request

Hi ,

Is there any easy way to parameterize the array element in Heirarchical ways in SOAPUI , my SOAP default Request will have like below and i want to parameterize by any datasource or using groovy script like below given codes .
<parent>
<name>Dad1</name>
<age>50</age>
<child>
<name>Son1</name>
<age>30</age>
</child>
</parent>

parent and child element is array element declared in WSDL .
So some time i want to pass

<parent>
<name>Dad1</name>
<age>50</age>
<child>
<name>Son1</name>
<age>30</age>
</child>
<child>
<name>Son2</name>
<age>25</age>
</child>
</parent>

and some time
Request 1:

<parent>
<name>Dad1</name>
<age>50</age>
<child>
<name>Son1</name>
<age>30</age>
</child>
<child>
<name>Son2</name>
<age>25</age>
</child>
</parent>

Reuqest 2 :

<parent>
<name>Dad1</name>
<age>50</age>
<child>
<name>Son1</name>
<age>30</age>
</child>
</parent>
<parent>
<name>Dad1</name>
<age>50</age>
<child>
<name>Son1</name>
<age>30</age>
</child>
<child>
<name>Son2</name>
<age>25</age>
</child>
</parent>

Let me know if you need any more information . Thanks in advance. Happy Testing
  • MartinS's avatar
    MartinS
    Occasional Contributor
    Actualy i dont realy know what you want... So can you give a litle bit more information?

    So u have default request - something like this:
    <parent>
    <name>Dad1</name>
    <age>50</age>
    <child>
    <name>Son1</name>
    <age>30</age>
    </child>
    </parent>


    And you want to randomly generate number of parents with children or you want to generate xml, based on data from data source?

    Examples:
    Randomly
    <parent>
    <name>Dad1</name>
    <age>random_value</age>
    <child>
    <name>Son1</name>
    <age>random_value</age>
    </child>
    <child>
    <name>Son2</name>
    <age>random_value</age>
    </child>
    </parent>
    <parent>
    <name>Dad2</name>
    <age>random_value</age>
    <child>
    <name>Son1</name>
    <age>random_value</age>
    </child>
    </parent>


    XML based on data from data source
    Data source will get a row:
    Parent; parentAge, son1; son1Age; son2, son1Age;
    dad1;50;son1;15;son2;20;

    Then groovy sctip will generate XML based on data, in this example:
    <parent>
    <name>Dad1</name>
    <age>50</age>
    <child>
    <name>Son1</name>
    <age>15</age>
    </child>
    <child>
    <name>Son2</name>
    <age>20</age>
    </child>
    </parent>



    Regards,
    MartinS
  • arshwarsi's avatar
    arshwarsi
    New Contributor
    Thanks Martin for replying. Sorry for confusion. I will make it easy .Because this question's answer can help lots of people using SOAPUI

    <ns1:People xmlns:ns1="http://www.example.org/ParentChildGrandChild">
    <ns1:Person>
    <ns1:Name>Dad1</ns1:Name><ns1:Age>50</ns1:Age>
    <ns1:Child>
    <ns1:Name>Son1</ns1:Name>
    <ns1:Age>30</ns1:Age>
    <ns1:Child>
    <ns1:Name>Son1'sDaughther</ns1:Name>
    <ns1:Age>3</ns1:Age>
    </ns1:Child>
    </ns1:Child>
    </ns1:Person></ns1:People>

    First i want to parameterize from datasource name like Dad1, Son1 and age like 50, 30 of parent and child.
    The scenario is little tricky.
    Second for easy , child is array element .First request is as above , but in second request Dad1 will have two children named Son1 and Son2 and also Son1 and Son2 will be having one or many children. So like wise in each run number of children will vary ,...
    Just assume this generation hierarchy . So request will be dynamic based on number of children taken from datasource.
  • MartinS's avatar
    MartinS
    Occasional Contributor
    I think there are 2 options (the only 2 options i know ):

    First make a XML with multiple parents and sons and their sons ect... For example XML will containt 10 parents every parent will have 10 children. Then you can have data source which will get data from excel sheet. Then link Test Request with data source.

    Example:
    Excel sheet example:


    Data source will import first row. Then you will have xml request like this (this is only small example):


    <ns1:People xmlns:ns1="http://www.example.org/ParentChildGrandChild">
    <ns1:Person>
    <ns1:Name>${import_data#parentName}</ns1:Name><ns1:Age>${import_data#parentAge}</ns1:Age>
    <ns1:Child>
    <ns1:Name>${import_data#ChildName1}</ns1:Name>
    <ns1:Age>${import_data#ChildAge1}</ns1:Age>
    </ns1:Child>
    <ns1:Child>
    <ns1:Name>${import_data#ChildName2}</ns1:Name>
    <ns1:Age>${import_data#ChildAge2}</ns1:Age>
    </ns1:Child>

    </ns1:Person></ns1:People>



    The point is that XML will have around 10 parents and every parent will have 5 children (the number of parents and children depend on you).
    Then in Test Request property set Remove Empty Content on true. This will clear all empty XML elements. So when you dont have value in excel sheet then XML element will be empty and this will remove all of them.

    Example:
    I tryed to attach picture of example excel sheet. It should be somewhere above. There are 2 parents with 2 children each. So XML will have 2 parents with 2 children and values will be mapped to data source as example above. All values will be send to Test Request and fill all fields in there. Then Remove empty content remove all empty elements so you will get clean XML with same number of parents/childs set in your excel sheet.


    The second:

    Same principle but this one use java library (only for SoapUI Pro 4.5.0). I am using this option only when i cant use remove empty content (for example when you have in test request empty element msgParams which cant be deleted).


    Regards,
    MartinS