Forum Discussion

ak0032803's avatar
ak0032803
Contributor
16 years ago

Re: How to set property values in a loop

hi,

I have created a test using SOAPUI having following scenario -

1-Datasource
2-Properties
3-GroovyScript to generate data
4-Request
5-Loop to data source.

In the request I have to send multiple elements in format-


 
  00000000-0000-0000-0000-000000000000
  Test3
 


  00000000-0000-0000-0000-000000000000
  Test4
 


I dont know how many inputs are there for this node.


I am using following script to achieve this -

def gu = new com.eviware.soapui.support.GroovyUtils( context )
def frag = context.expand('${Properties#SecurityGroupArray}')
def S1 ="Test3,Test4,Test5"
def String [] Array = S1.split(",");
for ( int i=0;i {
def Mystring  = Array;
   
log.info(Array);

gu.setPropertyValue('Properties', 'SecurityGroupArray', "${frag}00000000$Mystring" );
log.info(Mystring);
log.info(frag);
}

It generates the property value for last string only.

I have stored it in excel as "Test1,test2,Test3"
I want to split the string and generate the o/p as


00000000
Test3



00000000
Test4


Please let me know if I am missing something....

2 Replies

  • M_McDonald's avatar
    M_McDonald
    Super Contributor
    Try this

    def gu = new com.eviware.soapui.support.GroovyUtils( context )
    def frag = ""
    def S1 ="Test3,Test4,Test5"
    for ( key in S1.split(",") )
    {
      frag += "<SecurityGroup><SecurityGroupNameId>00000000</SecurityGroupNameId><SecurityGroupKey>$key</SecurityGroupKey></SecurityGroup>"
    }
    gu.setPropertyValue('Properties', 'SecurityGroupArray', frag)