php - Groovy script for test steps in SoapUI -
in soapui (pro version) have 12 test steps:
get
request- groovy script witch
total
value response previous step - properties
- properties transfer
post
request 1post
request 2post
request 3post
request 4post
request 5post
request 6post
request 7post
request 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