Forum Discussion

Awesome's avatar
Awesome
Frequent Contributor
16 years ago

Merge property 'string' with groovy 'list'

hi, thanks in advance for you help!

i have a groovy script that loops around a request and builds a List [] from the elements in a response. for each iteration it reads/stores the List in a Property step (as a string i assume?) .

test case layout:
property step
operation
groovy step (method which calls a "looping" class from the external script library)

questions:
1) i'm using the property step to store the values retrieved after each iteration through the operation response. instead of using the property step as an "external global variable", is there a better way to aggregate all the response results during the looping? (it seems each time i leave the groovy class to loop around the operation step, i lose any values stored in the script, that's why i'm using the property step since it's external to the loop...)

2) the final result is stored in the property step as such: [a,b,c,d][e,f,g,h][i,j,k,l]. i'd like to store the final result as one list: [a,b,c,d,e,f,g,h,i,j,k,l]. i think the issue is that with each loop i'm reading in a "string" from the property step and writing it back as a string???

def prop []
def results []

prop = expand property R <--- is prop treated as a string or a list?
elements = response elements
for i in elements { results << it }
prop = prop + results <--- this is where i try to "merge" the property string with the next list iteration
(or i tried prop = prop << results , still same results [][][])
store prop in property R
loop out to the operation step and run again.

1 Reply

  • Perhaps the best way would be to form a new list with each loop, and copy that to the property.