php - Groovy script for test steps in SoapUI -
in soapui (pro version) have 12 test steps:
getrequest- groovy script witch 
totalvalue response previous step - properties
 - properties transfer
 postrequest 1postrequest 2postrequest 3postrequest 4postrequest 5postrequest 6postrequest 7postrequest 8
all post requests have id parameters.
question:
how write groovy script or maybe decision way:
if total = 8 set id parameters of post 1 = 1,post 2 = 1,post 3 = 1,post 4 = 1,post 5 = 1,post 6 = 1,post 7 = 1,post 8 = 1 if total = 7 set id parameters of post 1 = 2,post 2 = 1,post 3 = 1,post 4 = 1,post 5 = 1,post 6 = 1,post 7 = 1 if total = 6 set id parameters of post 1 = 2,post 2 = 2,post 3 = 1,post 4 = 1,post 5 = 1,post 6 = 1 if total = 5 set id parameters of post 1 = 2,post 2 = 2,post 3 = 2,post 4 = 1,post 5 = 1 if total = 4 set id parameters of post 1 = 2,post 2 = 2,post 3 = 2,post 4 = 2 if total = 3 set id parameters of post 1 = 3,post 2 = 3,post 3 = 2 if total = 2 set id parameters of post 1 = 4,post 2 = 4 if total = 1 set id parameters of post 1 = 8      
you use following in groovy [step 2]
def totalpoststeps = 8 def totalfromresponse = 7 //map 1 got prev response def postidarray = new int[totalpoststeps] def index = 0 1.upto (totalpoststeps, {     postidarray[index]+=1;     index = index==totalfromresponse-1?0:index+1 }) //log.info postidarray.tostring() postidarray.eachwithindex{num, idx ->      def numstring = num!=0?num.tostring():""      //the next step create/update properties in testcase custom properties , u can map these directly post requests      //or can set these directly step3 , continue step 4      testrunner.testcase.setpropertyvalue("idforpost_"+(idx+1), numstring)    }      
Comments
Post a Comment