Forum Discussion

lucky009's avatar
lucky009
New Contributor
11 years ago

Groovy sql data to loop the request

Hello All,

I need to retrieve data from DB table, store in property, pass it REST request and loop through based on sql query result set.

1) Groovy script to retrieve result (potentially 10 or more records)
row = sql.eachRow(query)

2) Store at Property level (eg; testRunner.testCase.testSuite.setPropertyValue("AccountId",accountId.toString())

3) Invoke the REST request by passing the property value


4) Go To Step 1 and repeat 2 & 3 for remaining records as well.

My problem is i can get the first row, store the value and invoke the REST request. But i don't know how to loop groovy script based on sql record set.

If my sql query returns 10 rows, then my test suite should loop through 10 times.

Can you please enlighten me on how to accomplish this?

Thanks

1 Reply

  • nmrao's avatar
    nmrao
    Community Hero
    May be you can do even running the REST step from groovy itself.

    sql.eachRow( 'select * from tableName' ) {
    // do the stuff here here
    // set property
    // run REST step

    }