Forum Discussion

zkerbo's avatar
zkerbo
New Contributor
7 years ago
Solved

Property Transfer Question

Hello,

 I have a TestCase where I need to generate x number of unique strings. Let's say 10 email addresses. The way I am doing things now is I have 10 groovy script test steps that randomly create the email string and 10 Transfers. Is there a way to condense this? If I have one groovy script that generates the random string can I just evaluate it each time I do a property transfer? I have 6 other strings I need to generate as well (FirstName, LastName, etc...) so the way I am currently doing things I would have 70 test steps just for generating data. 

Thanks!

  • I typically create a properties step and use a groovy script to write my properties to that with a groovy test step. If I need multiple of the same value per request, I name them differently.

     

    Example:

    CustomerEmail

    ManagerEmail

    etc.

     

    If I need multiple data-sets for multiple requests, I'd have:

    CustomerEmail1

    ManagerEmail1

    CustomerEmail2

    ManagerEmail2

     

     

    Then in my groovy script I have a for-loop that iterates through how many data-sets I need, and generates how many elements I need per dataset.

     

    Here's a very quick groovy script example. 

     

     

    def propertiesStep = testCase.testSteps["Properties"];
    
    def generateEmail()
    {
         // insert email generation script here
    } for(int i = 1; i < 100; i++) { propertiesStep.setPropertyValue("CustomerEmail" + i, generateEmail()); propertiesStep.setPropertyValue("ManagerEmail" + i, generateEmail());
    i++; }

     

4 Replies

  • groovyguy's avatar
    groovyguy
    Champion Level 1

    I typically create a properties step and use a groovy script to write my properties to that with a groovy test step. If I need multiple of the same value per request, I name them differently.

     

    Example:

    CustomerEmail

    ManagerEmail

    etc.

     

    If I need multiple data-sets for multiple requests, I'd have:

    CustomerEmail1

    ManagerEmail1

    CustomerEmail2

    ManagerEmail2

     

     

    Then in my groovy script I have a for-loop that iterates through how many data-sets I need, and generates how many elements I need per dataset.

     

    Here's a very quick groovy script example. 

     

     

    def propertiesStep = testCase.testSteps["Properties"];
    
    def generateEmail()
    {
         // insert email generation script here
    } for(int i = 1; i < 100; i++) { propertiesStep.setPropertyValue("CustomerEmail" + i, generateEmail()); propertiesStep.setPropertyValue("ManagerEmail" + i, generateEmail());
    i++; }

     

    • nmrao's avatar
      nmrao
      Champion Level 3
      Why to even have property transfer step again? Just wouldn't it be suffice to use test case properties and use property expansion?
    • zkerbo's avatar
      zkerbo
      New Contributor

      This seems like a good idea. I will try it, thanks!

      • groovyguy's avatar
        groovyguy
        Champion Level 1

        zkerbo: Thanks for the kudos! Let me know if you run into any more issues with it! I hope it works :D