cancel
Showing results for 
Search instead for 
Did you mean: 

Data driven testing - How to create and use a table data source with a groovy script?

Contributor

Data driven testing - How to create and use a table data source with a groovy script?

In ReadyAPI, I want to create a "table" of test data by using a Groovy Script block inside a Data Source block. I will generate the data for the "table" with custom logic/code. The "table" can have multiple columns and each row represents a set of test data.

I want to use the "table" in a data source loop & make a REST API call inside the loop. The API call should be able to access all the columns inside each row. To summarize, think of this as a groovy script which provides DataGenerator + Grid data sources.

So, how do I generate a table of data with a Groovy Data Source? Is there a recipe for this?

Keywords - data driven tests, Data Source, tabular test data, test data table.

7 REPLIES 7
Contributor

Re: Data driven testing - How to create and use a table data source with a groovy script?

Hi,

The licensed version of SoapUI/ReadyAPI does this out of the box and does it very well.  It's probably my favourite feature.

 

If you're using the open source version it can be achieved, but takes a bit of effort.  There are plenty of recipes/solutions on this forum and Stack Overflow which describe this how to do this.  I'm not going to link any particularly solution as its worth it to you to look at a couple of different solutions so see how this can be achieved.

 

Good luck,

 

Chris

Contributor

Re: Data driven testing - How to create and use a table data source with a groovy script?

I could not find any recipe or answer for my problem on this forum and also on stack overflow. In this forum I searched "groovy data source". In stack overflow, I searched "ready-api groovy data source" & "[ready-api] groovy data source". I could not find any posts which provide hints or a recipe.

 

So, do you know any better keywords to search or a solution to the problem?

 

Community Hero

Re: Data driven testing - How to create and use a table data source with a groovy script?

Hey @rajs2020,

Youre using ReadyAPI!, right?

Doesnt a datasource grid type get you some of the way there? If you want a table of data, a datasource step of grid type may help

Ta

Rich
if this helped answer the post, could you please mark it as 'solved'? Also if you consider whether the title of your post is relevant? Perhaps if the post is solved, it might make sense to update the Subject header field of the post to something more descriptive? This will help people when searching for problems. Ta
Contributor

Re: Data driven testing - How to create and use a table data source with a groovy script?

Hi @rajs2020,

 

I read your question incorrectly.  Thanks to @richie, I read it again. 

 

So, you have Ready API and with that you have Data Driven Tests?  It sound like you want to generate data on the fly AND use it as a source for your data driven test at the same time?  Am I getting closer?

 

Chris

Contributor

Re: Data driven testing - How to create and use a table data source with a groovy script?

Yes, I want to create my own "table"/"data grid" with code and then use its data to make some api calls repeatedly. I do not want to use the static/fixed data grid of ReadyAPI. Thanks.

This is the kind of code I expect:
DataSource:
"Table" tab = new Table()
//Code to fill the table.

DataSourceLoop:
Table tab = DataSource.getResult();
FOR each row, iterate through columns & use column values in to make api call in REST api step.

Contributor

Re: Data driven testing - How to create and use a table data source with a groovy script?

Why not an initial Groovy step that creates the data for the test and saves it to a file.  Then use plain old Data driven tests to read the data from the newly created file.

You don't have to use Ready API/Groovy to create the data, you could use whatever you want, but I suppose it would be tidier all in Ready API. 

 

Re "FOR each row, iterate through columns & use column values in to make api call in REST api step.", are you trying to make something truly dynamic that can fit any number of rows and columns?  If so, how are you going to build your payload based on the columns in the row?

Contributor

Re: Data driven testing - How to create and use a table data source with a groovy script?

Thanks. But, I don't want to create a file because it is unnecessary overhead & I only need to create 5-10 rows of data. ReadyAPI has its own data grid. I wonder if the code for that is available inside groovy script so that we can generate the grid ourselves too.

For the 2nd part, this is what I have in mind - The number of rows & columns are known, all rows must have the same number of columns and the table supports at least, say 100 rows (arbitrarily chosen). I haven't figured out how to build the api payload yet. I'm almost about to abandon this approach & let duplicate tests remain.

New Here?
Join us and watch the welcome video:
Announcements
Top Kudoed Authors