cancel
Showing results for 
Search instead for 
Did you mean: 

How to store value from groovy script into DataSource

New Contributor

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 4
Super Contributor

Re: How to store value from groovy script into DataSource

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.

New Contributor

Re: How to store value from groovy script into DataSource

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 ??

Super Contributor

Re: How to store value from groovy script into DataSource

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?

Community Manager

Re: How to store value from groovy script into DataSource

Hi @jeev,

 

Does @avidCoder's reply help you? If it does, please accept this post as a solution (a big green button). It will help other community members find the answer faster. Plus, avidCoder will get some points to his reputation!

---------
Tanya Gorbunova
SmartBear Community Manager

Did my reply answer your question? Give Kudos or Accept it as a Solution to help others.↓↓↓↓↓
New Here?
Join us and watch the welcome video:
6 / 7 API Testing Mistakes Video
Top Kudoed Authors