I did some cut-paste from some groovy examples online. After a lot of trials-and-errors and with the help of log.info, I can see that my groovy can now read the input CSV file row by row.
However, somehow it would not plug into the value into the teststep. I am certain that the problem lies in the properties definition.
I probably overcomplicated things by using property. The purpose of this groovy is just to read the MSISDN from a file in my C-drive and plugs it into the API (in this case, getSubscriptionInformation).
Please take a look and point out if you see any errors.
Thanks.
--------------------------------------------------------------------------------------------------------------------------------------------
import java.text.SimpleDateFormat
def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context)
def csvFilePath = "C:\\PT-Groovy\\msisdn-list.csv"
def reportFile = "C:\\PT-Groovy\\Reports\\results-20.log"
context.fileReader = new BufferedReader(new FileReader(csvFilePath))
File report = new File(reportFile)
rowsData = context.fileReader.readLines()
int rowsize = rowsData.size()
report.text = "Timestamp|MSISDN|MESSAGE"
for(int i =0; i < rowsize; i++)
{
def date = new Date()
def sdf = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss")
rowdata = rowsData[i]
String[] data = rowdata.split(",")
testRunner.testCase.setPropertyValue( "MSISDN", data[0] )
testRunner.runTestStepByName( "GetSubscriptionInformation")
tStep = testRunner.testCase.getTestStepByName("GetSubscriptionInformation")
def xmlResponse = tStep.getPropertyValue("Response")
def holder = groovyUtils.getXmlHolder(xmlResponse)
def MESSAGE = holder.getNodeValue("/S:Envelope/S:Body/ns2:getSubscriptionInformationResponse/resultData/msisdn")
log.info data[0]+"|"+MESSAGE
report << "\n"+sdf.format(date)+"|"+data[0]+"|"+MESSAGE
sleep(1000)
}
-------------------------------------------------------------------------------------------------------------------------------------------------
<soapenv:Body>
<api:getSubscriptionInformation>
<msisdn>${#TestSuite#MSISDN}</msisdn>
<!--
<iccid>${#TestSuite#ICCID}</iccid>
<imsi>${#TestSuite#IMSI}</imsi>
-->
</api:getSubscriptionInformation>
</soapenv:Body>
--------------------------------------------------------------------------------------------------------------------------------------