Forum Discussion

porcupineRabbit's avatar
porcupineRabbit
Occasional Contributor
4 years ago

Data Generator - Change "duplicate each value" property through Groovy

Hello all,

I have used a DataSource with DataGenerator type selected, in one of my test cases and I'm trying to set the "duplicate each value" property through a Groovy step. What I'm trying to achieve here is to set this value from a project-level custom property. The test case is setup as shown below and I have managed to go as far as this in my Groovy step:

 

def valueRepetition = context.expand('${#Project#repeatValue}')
def objDsStep = context.testCase.testSteps["Data Generator"]
// objDsStep is a com.eviware.soapui.impl.wsdl.teststeps.WsdlDataSourceTestStep
def objSource = objDsStep.getDataSource()
// objSource is a com.eviware.soapui.impl.wsdl.teststeps.datasource.DataGenerator.UI.DataGeneratorDataSource object

log.info(objSource.toString())

 

I've looked through the API documentation but I cannot find which method to call in order to retrieve the generator's properties and update the 'repetitionCount' method .

Can anyone provide some help on this?

 

Thanks in advance!

  • JKolosova's avatar
    JKolosova
    SmartBear Alumni (Retired)

    Hi porcupineRabbit,

    I have made a number of experiments but failed to find an easy way to modify the Duplicate Each Value parameter of the generator from the Groovy script so far. Can you please submit a case using this link so that we could perform a more thorough investigation and consult the developers?

    Also, please describe your testing scenario more precisely as there may be some other ways to achieve the goal.


    • porcupineRabbit's avatar
      porcupineRabbit
      Occasional Contributor

      Hello JKolosova ,

       

      thank you for your interest and yes, you are right. There is no easy way to do that, since "Geta Data" option is not available for this field when you right-click.

      I managed to develop a groovy function that performs this task, after a (rather long and thorough) research in old and new readyAPI / soapUI documentation pages! You can see the method below, but I will also open a support ticket as you suggested, so the dev team can investigate if this task can become less "tedious" (I had my fun share building this) ğŸ˜Š

       

       

      void setGeneratorDuplicateValue(WsdlDataSourceTestStep generatorStep, String propertyItem, int duplicationValue) {
      	DataSource oDataGen = generatorStep.getDataSource()
      	GeneratorDescriptor genDescriptor = oDataGen.getDescriptorForProperty(propertyItem)
      	PropertyTypeBasePanel  propTypeBase = genDescriptor.getTab()
      	
      	propTypeBase.setDuplicateValue(duplicationValue)
      	genDescriptor.setUpdated(true)
      	oDataGen.setGeneratorDescriptor(genDescriptor)
      	genDescriptor = null
      }
      
      // How to call it
      // def objDataGenStep = context.testCase.testSuite.getTestCaseByName("Test_Case_Name").testSteps["Data Generator"]
      // setGeneratorDuplicateValue(objDataGenStep,"autoNumber", neededRows)

       

      What  I am trying to achieve is:
      I perform some load tests and I have an excel file (data source) with the data rows needed. Each run needs a different number of rows, depending on the workload. The task is to change the duplicate values assigned from the Data Generator, according to the data rows. For example, if I set the data source to get 25 rows, the generator must duplicate the same number of values (25 that is), from a given set. If you need more insight please say so, since this is an already long post.

      Finally, it would be great if the ReadyAPI API documentation had some comments for the methods / objects available. If I can also open a support ticket for this, please let me know. 

      Thank you for your help