Forum Discussion

Andronicus's avatar
Andronicus
New Member
8 years ago

SoapUI Groovy Script DataSource

Hello,

 

I'm trying to make a groovy script for a data source that will iterate through an array of codes of size x and store them in the results.

 

This is the code I have so far

 __________________________________________________________________

List codeList = testRunner.testCase.getPropertyValue("rightCode").split(/ /)


def size = codeList.size()

 

for (i = 0; i< size; i++)
{
result["rightCode"] = codeList.get(i)
}

___________________________________________________________________

 

The problem with this is whenever the results displays it will display for example if the original array was size 10, it will store 10 of the last element in that array instead of all of the elements.

 

I think the problem might be that I have I do not know what code to use to get to the next row so it doesnt keep writing over row 1?

 

 

1 Reply

  • I don't think that's how Groovy DataSource works.

    Because each row is an execution of the Script that you wrote, each row iterates and gets the last result.

     

    Tested using code below: (each row returned different results, meaning to say, each row executed the script on their own)

     

    char[] chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ123456789".toCharArray();
    StringBuilder sb = new StringBuilder();
    Random random = new Random();
    for (int i = 0; i < 20; i++) {
        char c = chars[random.nextInt(chars.length)];
        sb.append(c);
    }
    String output = sb.toString();
    result["data"] = output

    so if you try to loop, the loop will end and will return the last data, that happens on each row.