Forum Discussion

ADucci's avatar
ADucci
Occasional Contributor
15 years ago

Data Driven Testing - Repeating Complex Elements

HI,

I Am looking to create a data driven test, where each test step record contains a repeating complex element ( ie a person having contact details)

please can you note the high level steps i would take to complete this, i dont mind reading up, its just that i have no idea where to start.

Attached, a sample message, having repeating nodes.


[color=#8000FF]<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:element name="Person">
<xs:annotation>
<xs:documentation>Comment describing your root element</xs:documentation>
</xs:annotation>
<xs:complexType>
<xs:sequence>
<xs:element name="Name" type="xs:string"/>
<xs:element name="Surname" type="xs:string"/>
<xs:element name="Contacts" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="ContactText" type="xs:string"/>
<xs:element name="Code" type="xs:string" minOccurs="0"/>
<xs:element name="ContactType" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>[/color]
  • ADucci's avatar
    ADucci
    Occasional Contributor
    Just thinking, a possible solution would be to add an additional datasource containing the "children" data. then filter this list for each iteration of the "Parent"

    is it possible to filter a datasource in runtime?

    i see this topic touches on the requirement...

    http://www.eviware.com/forum/viewtopic.php?f=2&t=4797

    Please help...
  • M_McDonald's avatar
    M_McDonald
    Super Contributor
    I think you are on the right track; you can certainly change the content of the child datasource.

    As far as using repeated elements I have used this sort of test structure:

    Person DataSource
    Contacts DataSource
    Contacts Script (Groovy)
    Contacts DataSource Loop
    Properties Step
    Request
    Reset Script (Groovy)
    Person DataSource Loop


    The Contacts datasource would contain the repeating contact information. The Contacts script step would have code to aggregate the contacts into an XML fragment which is stored as a property in the Properties step.

    def gu = new com.eviware.soapui.support.GroovyUtils( context )

    def contactText = context.expand( '${Contacts DataSource#contactText}' )
    def code = context.expand( '${Contacts DataSource#code}' )
    def contactType = context.expand( '${Contacts DataSource#contactType}' )

    def frag = context.expand('${Properties#xmlFragment}')
    frag += """<Contacts><ContactText>${contactText}<ContactText>
    <Code>${code}</Code>
    <ContactType>${contactType}</ContactType>
    </Contacts>
    """
    gu.setPropertyValue('Properties', 'xmlFragment', "${frag}" )


    which will put something like the following in the Properties step:

    <Contacts><ContactText>Able<ContactText> <Code>1</Code> <ContactType>A</ContactType> </Contacts> 
    <Contacts> <ContactText>Baker<ContactText> <Code>2</Code> <ContactType>B</ContactType> </Contacts>
    <Contacts> <ContactText>Charlie<ContactText> <Code>3</Code> <ContactType>C</ContactType> </Contacts>
    <Contacts> <ContactText>Delta</ContactText> <Code>4</Code> <ContactType>D</ContactType> </Contacts>


    Then the request can use a property expansion to include the aggregated XML.
    ...
    <Person>
    <Name>${Person DataSource#name}</Name>
    <Surname>${Person DataSource#surname}</Surname>
    ${Properties#xmlFragment}
    </Person>
    ...


    The Reset step would simply clear out the xmlFragment before the next loop through the Person datasource.
  • ADucci's avatar
    ADucci
    Occasional Contributor
    Wow... great! thanks for the excellent response...

    the only thing is, my contacts datasource has many person phone records, for many persons. the script would have to ignore un-related persons...

    is there a way to filter the contacts to show only each relevant person's contact info ( as dictated by the person datasource - current record)

    thanks

    Anthony
  • ADucci's avatar
    ADucci
    Occasional Contributor
    looking at using the Netbeans Plugin, maybe it will make the process easier..

    still struggling tho!
  • ADucci's avatar
    ADucci
    Occasional Contributor
    Hi..

    got it working, all i needed to do, was put an if statement into the Groovy Script to check if each child element is applicable for every parent
    if ( Parent_SA_ID.equals(Child_SP_ID) )
    (then print out data)

    Problem is that this takes a long time, as the child table needs to be looped for every parent record?

    Is there a way to perform a query in datasource that uses a Groovy Script


    def gu = new com.eviware.soapui.support.GroovyUtils( context )
    def Parent_SA_ID = context.expand( '${PersonDataSource#PerID}' )

    * then select all records in the Contacts Table Based on a query *
    "Select *
    from Contacts
    where per_ID = '${PersonDataSource#PerID}'