Forum Discussion

LennSar's avatar
LennSar
Contributor
2 years ago

groovy data source loop

Hi there,

 

typically when using the data source I can set the amount of rows that shall be generated and with that how many times the loop should occur. Now I try to generate a data source using a groovy script with 3 rows but I can't figure out how to set this 3 rows as there is no field of "number of rows" as for i.e. the data Generator. 

Could you please tell me how I can set and read this parameter when using a groovy Data Source or is the groovy Data Source not ment to be used with loops?

 

Thanks!

 

Lennart

9 Replies

  • groovyguy's avatar
    groovyguy
    Champion Level 1

    The way I handle this is to create a primary data source that is a grid, and I fill it with how many rows of  data that I need to process. It would look something like this:

     

    Count Data Source (set with 1 property, X rows, where the data does not matter.)

               Groovy Script Data Source

               Tests using GS data Source

    Data Source Loop using Count Data Source as its control, and pointed at GS Data Source for its test step.


    This way the Count Data Source will control how many iterations you have.

     

     

    • LennSar's avatar
      LennSar
      Contributor

      Hi groovyguy,

       

      thanks for the tip. I solved various issues with a similar approach but was hoping for some groovy command being able to determine the amount of rows generated. Well, this approach will certainly work as well.

      Could you just tell me how you generate several rows in the grid dataSource (which I assume is the dataSource you named GroovyDataSource above?).

      I know I can write a single value to a DataSourceProperty with 

      result["DataSourceProperty"] = someValue

       

      but how do I generate several lines? Can I simply use the index operator like 

       

      result["DataSourceProperty"][0] = someValue[0]
      result["DataSourceProperty"][1] = someValue[1]
      result["DataSourceProperty"][2] = someValue[2]

       

      Thanks a lot for the quick help!

       

      Cheers,

       

      Lennart

      • groovyguy's avatar
        groovyguy
        Champion Level 1

        LennSar Not a problem! Always happy to help.

        If I understand your next question, you want to generate 3 rows at once from the Groovy Data Source and access those all at the same time? I am not sure you can do that all at once. I haven't figured out a way, at least.

        You could create a loop within your groovy datasource and triplicate your properties, but even that seems convoluted and messy in the long term.

         

        If I might ask, what is your use case with needing three rows from the data source at once?