Tags
Running SoapUI Standard version with DataSource and DataLoop groovy
This is what goes into the DataSource groovy file.
/* @Author : Dan Birsan @Description : Data Source to read .csv file and pass the value to corresponding property. @GroovyTestStepName : "DataSource" */ import com.eviware.soapui.support.XmlHolder def myTestCase = context.testCase def counter,next,previous,size File tickerEnumFile = new File("T:\\Dan\\FTC HL7 - UC8 Test Data 2014-05-21 Random_2.csv") //make sure input.txt file already exists and contains different set of values sepearted by new line (CR). List lines = tickerEnumFile.readLines() size = lines.size.toInteger() propTestStep = myTestCase.getTestStepByName("Properties") // get the Property TestStep propTestStep.setPropertyValue("Total", size.toString()) counter = propTestStep.getPropertyValue("Count").toString() counter= counter.toInteger() next = (counter > size-2? 0: counter+1) tempValue = lines[counter] //Split the first line into a string array and assign the array elements to various test case properties String[] propData = tempValue.split(",") propTestStep.setPropertyValue("HL7EventType", propData[0]) propTestStep.setPropertyValue("SendingFacility", propData[2]) propTestStep.setPropertyValue("memIDNum", propData[4]) propTestStep.setPropertyValue("PatientIDAssigningAuthority1", propData[5]) propTestStep.setPropertyValue("PatientIDAssigningAuthority2", propData[8]) propTestStep.setPropertyValue("PatientIDAssigningAuthority3", propData[12]) propTestStep.setPropertyValue("PID", propData[7]) propTestStep.setPropertyValue("PIDType", propData[11]) propTestStep.setPropertyValue("Surname", propData[13]) propTestStep.setPropertyValue("Givename", propData[14]) propTestStep.setPropertyValue("DOB", propData[15]) propTestStep.setPropertyValue("Gender", propData[16]) propTestStep.setPropertyValue("StreetAddress", propData[17]) propTestStep.setPropertyValue("City", propData[18]) propTestStep.setPropertyValue("State", propData[19]) propTestStep.setPropertyValue("PostalCode", propData[20]) propTestStep.setPropertyValue("Telephone", propData[21]) propTestStep.setPropertyValue("AreaCode", propData[22]) propTestStep.setPropertyValue("PID_OID", propData[23]) propTestStep.setPropertyValue("Count", next.toString()) next++ // log.info "Reading line : ${(counter+1)} / $lines.size" propTestStep.setPropertyValue("Next", next.toString()) // log.info "Value '$tempValue' -- updated in $propTestStep.name" if (counter == size-1) { propTestStep.setPropertyValue("StopLoop", "T") // log.info "Setting the stoploop property now..." } else if (counter==0) { def runner = new com.eviware.soapui.impl.wsdl.testcase.WsdlTestCaseRunner(testRunner.testCase, null) propTestStep.setPropertyValue("StopLoop", "F") } else { propTestStep.setPropertyValue("StopLoop", "F") }
And this is what goes into the DataLoop groovy file.
/* @Author : Dan Birsan @Description : Data Source Looper responsible for looping a specific teststep. @GroovyTestStepName : "DataLoop" */ def myTestCase = context.testCase def runner propTestStep = myTestCase.getTestStepByName("Properties") // get the Property TestStep endLoop = propTestStep.getPropertyValue("StopLoop").toString() if (endLoop.toString() == "T" || endLoop.toString()=="True" || endLoop.toString()=="true") { log.info ("Exit Groovy Data Source Looper") assert true } else { testRunner.gotoStepByName("DataSource") //setStartStep }