cancel
Showing results for 
Search instead for 
Did you mean: 

repeating elements when using xls datasource?

Contributor

repeating elements when using xls datasource?

Hi,

Is it possible using a spreadsheet to test the cardinality of the repeating element? For example, one of our elements has a repeating child element:

...

             
             
                        ?
                          ?
             

             

...


I would like to generate the requests below


Scenario 1:
...

             

...


Scenario 2:
...

             
                        1
                          Prod1
             

             

...


Scenario 3:
...

             
                        1
                          Prod1
             

             
                        2
                          Prod2
             

             

...


Is this possible using a spreadsheet or should I be considering a file datasource with the different xml requests needed? 

We have to run about 1000 scenarios (and some of our messages will have hundreds of elements per message) so I'd rather  maintain a spreadsheet than 1000 xml files.

thanks for your advice

..Garret
4 REPLIES 4
Super Contributor

Re: repeating elements when using xls datasource?

Hi Garret,

hmm.. is the number of CustomerOrderItem elements fixed or can it change for each request?

- If it's fixed, you could create a groovy script that assigns the values
- If it's dynamic, the groovy script would also have to create the xml for each item and then insert the whole block into the request

regards,

/Ole
eviware.com
Contributor

Re: repeating elements when using xls datasource?

Hi Ole,

In the live environment the number of elements will change per request. In testing it would be sufficient if we always test 2 elements.

How would you suggest we arrange our spreadsheet & groovy script?

Is it possible to have the main request fields in one worksheet, then reference another worksheet per repeatable element perhaps?
Super Contributor

Re: repeating elements when using xls datasource?

Hi,

hmm.. if you want to add all rows in your datasource to one request you could do as follows:

1) DataSource
2) Groovy script that aggregates and builds xml
3) DataSourceLoop back to (2) for each row in (1)
4) Request that uses aggregated xml

The key here obviously being the script in (2), something like

// get existing..
def xml = context.xml
if( xml == null )
  xml = ""

// aggregate row
xml += "<CustomerOrderItem><Id>"
xml += context.expand( "${DataSource#id}"  )
xml += "</Id><Name>"
xml += context.expand( "${DataSource#name}"  )
xml += "</Name></CustomerOrderItem>"

// save
context.xml = xml


In your request you could then have the following xml:

<CustomerOrder>
            ${xml}
</CustomerOrder>


makes sense?

regards!

/Ole
eviware.com
Contributor

Re: repeating elements when using xls datasource?

Understood Ole,

Thank you

..Garret
New Here?
Join us and watch the welcome video:
6 / 7 API Testing Mistakes Video
Top Kudoed Authors