Forum Discussion

ushaplaxo's avatar
ushaplaxo
Contributor
14 years ago

How to pass an array?

How do I pass an array as a paramater value in my test step?

Here is what I am doing:

1. Running a test step from which I get 4 ids - id1, id2, id3, id4
2. I store those 4 ids in a data sink
3. I have to split those 4 ids into a group of 2 and pass it in the form of an array in my next test step

Here is my parameter itemid which takes an array

itemid: [{"itemCount":2,"itemstring":"id1,id2"},{"itemCount":2,"itemstring":"id3,id4"}]

How can I do this?

Thanks
Usha
  • Hi,

    if your example always uses 4 ids split on two than here is you script


    def ids = "id1, id2, id3, id4";
    def x = ids.indexOf( ",", ids.indexOf( "," )+1);

    def first = ids.substring(0,x)
    def second = ids.substring(x+1, ids.length())

    def myresult = /itemid: [{"itemCount":2,"itemstring":"${first}"},{"itemCount":2,"itemstring":"${second}"}]/
    return myresult

    in next request just use property expansion ${Groovy Script#result}

    Hope this helps

    regards
    nebojsa
    eviware