Forum Discussion

jeev's avatar
jeev
New Contributor
6 years ago

How to store value from groovy script into DataSource

Using groovy script I have gathered all the ID one by one  from response.  I want to store these values into datasource, and pass them into next request, is it possible??

=========================================================

My script:

 

for ( j = 0 ; j < dresRows ; j++)
{

def response = context.expand( '${ABCD#Response#$['+j+'][\'href\']}' )

testRunner.testCase.testSteps["IdDataSource"].setPropertyValue("account_id", response)
}

 

DataSouce is Grid :

ERROR:

I am getting ERROR java.lang.runtimeException: Trying to set read-only property [account_id)

 

===================================

 

How to store value from groovy script into DataSource

 

4 Replies

  • avidCoder's avatar
    avidCoder
    Super Contributor

    DataSource is basically used to read-only the data not to store any data. You can use DataSink and update the value there. Just add 1 step as DataSink and replace "IdDataSource" with DataSink in code.

     

    Hope, this solves your problem.

    • jeev's avatar
      jeev
      New Contributor

      Its kind of solved my problem. I want to loop the ID into my next REST request step. 

       

      Now I have to store my IDs into DataSink Excel and Load the data (IDs) into  datasource in my next step

       

      is there any other easy way to do it ??

      • avidCoder's avatar
        avidCoder
        Super Contributor

        As per my knowledge. you cannot write anything to DataSource but you can set the property value in DataSource like this:-

         

        def response = context.expand(${Request#Response})
        testRunner.testCase.testSteps["DataSource"].setPropertyValue("Response", response)

        So, here if you are getting ID's at every loop, put this code there (Do some changes in code with respect to ID) inside for loop and store the ID's at DataSource property.

         

        Does it sound good to you?