Forum Discussion

LennSar's avatar
LennSar
Contributor
3 years ago

Data Source with random amount of lines

Hi there,

I'd like to generate some dummy data using the Data Source / Loops functionality. It is important though to randomize the amount of data generated. Is there a way to do that with the data source; Data Generator or is this a case to get groovy?

  • You can create a property to generate a random number, then pass that property into the number of rows in your datasource test step.

    I included a screenshot below that does this in a completely codeless approach. Under TestCase1 under RestProject 30 I have three test steps. 
    DataGen generates a random value between 5 and 10.
    The GroovyScript prints out the value of the random number. 
    And finally the datasource returns a number of rows equal to the random number. 

    Here are the results in RAPI.

     



    Hope this helps. 

  • You can create a property to generate a random number, then pass that property into the number of rows in your datasource test step.

    I included a screenshot below that does this in a completely codeless approach. Under TestCase1 under RestProject 30 I have three test steps. 
    DataGen generates a random value between 5 and 10.
    The GroovyScript prints out the value of the random number. 
    And finally the datasource returns a number of rows equal to the random number. 

    Here are the results in RAPI.

     



    Hope this helps. 

  • Awesome thanks a lot SarahS . I've never used the DataGen before and according to the documentation it is deprecated. Anyways: You can use a DataSource instead of a DataGen just the same way you showed it in your post.

     

    Really appreciate your help!

  • The main goal is to create some kind of randomized property. Instead of using DataGen you could use the data generator DataSource to generate one row of random data. Another alternative to DataGen is to create a property (use the Properties test step) that calls a Math.random() type function.