Forum Discussion

rajs2020's avatar
rajs2020
Frequent Contributor
4 years ago

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

  • ChrisAdams's avatar
    ChrisAdams
    Champion Level 3

    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

    • rajs2020's avatar
      rajs2020
      Frequent Contributor

      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?

       

      • richie's avatar
        richie
        Community Hero
        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
  • ChrisAdams's avatar
    ChrisAdams
    Champion Level 3

    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

    • rajs2020's avatar
      rajs2020
      Frequent Contributor

      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.

      • ChrisAdams's avatar
        ChrisAdams
        Champion Level 3

        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?