Forum Discussion

steve_rivers's avatar
steve_rivers
Occasional Contributor
12 months ago

Auto-Populate Data Generator "Value from set" values

Is there anyway to automatically populate the values list in the "Value from set" option in the Data Generator section of the Data Source step? Digging through the API definition for the DataGenerato...
  • nmrao's avatar
    12 months ago

    One can use own groovy data source to generate in such situation.

    For example there are many departments in an organization and want to use one of its value randomly.

    Here the script goes:

    def rand = new Random()
    def departments = ['HR', 'Fecilities', 'R&D', 'Services', 'Security', 'IT', 'Sales', 'Marketing', 'Finance']
    def getRandomDepartment = {  departments[rand.nextInt(departments.size -2) + 1]  }
    
    log.info getRandomDepartment()

    To give some more idea, generate employee data, say: 

    //Sample data source generation using department 
    log.info "Employee ID, Department"
    (1..10).each { log.info "$it, ${getRandomDepartment()}" }

     You can quickly try executing the same here