Read csv file in groovy
following code snippet can be used to read csv file in groovy language
// Define your Test Case number and “Test Data file in next two lines
testRunner.testCase.setPropertyValue(“TestCaseNo”,”TC004″)
def csvFilePath = “C:\\SRTemp\\abc.txt”
// No changes in code below:
def TestCaseNo = testRunner.testCase.getPropertyValue(“TestCaseNo”)
def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context)
// Iterate through each row in Test Data file
File file = new File(csvFilePath.toString()).eachLine{
testRunner.testCase.setPropertyValue(“TCN”,it.split(“,”)[0])
def TestNo = testRunner.testCase.getPropertyValue(“TCN”)
if(TestNo==TestCaseNo){
context.testCase.setPropertyValue(“policynumber”, it.split(“,”)[1])
context.testCase.setPropertyValue(“policydate”, it.split(“,”)[2])
}
sleep 500
}
Assumption here is:
- There exists a file “c:\\abc.csv” on local file system
- Headers in above files contains COUNTRY, CAPITAL fields
0 comments