Forum Discussion

electric_Insura's avatar
electric_Insura
Contributor
14 years ago

Script assertion - iterate through Datasource properties?

I have script assertions in a JDBC request step.

Since the request can return multiple database rows for a key, I need to validate the content of each row against a datasource.

For each column in the table, I have datasource properties like PTD_NAME_0, PTD_NAME_1, PTD_NAME_2, which give expected results for each row for a given key.

I am using an Excel datasource.

I would like to do something like this... pseudocode follows.

For (i = 0, i++) {
currentName = context.expand ( PTD_NAME_i )
}

I don't know how to

a) get all the datasource properties to be available to the script assertion
b) construct the context.expand statement on the fly.

Any help appreciated, including more efficient ways to do this - thanks.

2 Replies

  • Hi,

    Can you give us a more concrete example? Maybe post a full (or shortened) XML response, together with the contents of your Excel datasource, and how the assertions should be done? I think that would make it easier for us to see how it should best be done.

    Regards,
    Dain
    SmartBear Software
  • XML:


    <Results>
    <ResultSet fetchSize="0">
    <Row rowNumber="1">
    <PTD_POLICY_NUMBER>IF44514H7</PTD_POLICY_NUMBER>
    <PTD_DATE/>
    <PTD_ANIMAL_TYPE>A</PTD_ANIMAL_TYPE>
    <PTD_ANIMAL_BREED>18</PTD_ANIMAL_BREED>
    <PTD_ANIMAL_COUNT>1</PTD_ANIMAL_COUNT>
    <PTD_POLICYHOLDER_SSN>918179825</PTD_POLICYHOLDER_SSN>
    <PTD_REC_CREATE_DATE>20110912</PTD_REC_CREATE_DATE>
    </Row>
    <Row rowNumber="2">
    <PTD_POLICY_NUMBER>IF44514H7</PTD_POLICY_NUMBER>
    <PTD_DATE/>
    <PTD_ANIMAL_TYPE>B</PTD_ANIMAL_TYPE>
    <PTD_ANIMAL_BREED>05</PTD_ANIMAL_BREED>
    <PTD_ANIMAL_COUNT>1</PTD_ANIMAL_COUNT>
    <PTD_POLICYHOLDER_SSN>918179825</PTD_POLICYHOLDER_SSN>
    <PTD_REC_CREATE_DATE>20110912</PTD_REC_CREATE_DATE>
    </Row>
    </ResultSet>
    </Results>


    Groovy script below. As you can see, I'm expanding all of the Datasource properties that I will need for that particular assertion. If I wanted to check PTD_ANIMAL_BREED, I'd be expanding all of the Datasource properties named PTD_ANIMAL_BREED_x.


    def pTD_ANIMAL_TYPE_0 = context.expand( '${DataSource#PTD_ANIMAL_TYPE_0}' )
    def pTD_ANIMAL_TYPE_1 = context.expand( '${DataSource#PTD_ANIMAL_TYPE_1}' )
    def expectedAnimalTypes = [pTD_ANIMAL_TYPE_0, pTD_ANIMAL_TYPE_1]
    def responseAsXml = context.expand( '${JDBC Request#ResponseAsXml}' )
    def results = new XmlSlurper().parseText(responseAsXml)
    ...