Read CSV file as library file in SoapUI
Step 1: create a groovy file on your file system (say: C:\\SRTemp\\abc.txt)
—————————————————————————–
TESTCASENO,COUNTRY,CAPITAL
TC004,0152935633,2019-05-05
Step 2: create a CSVReader.groovy with following contents:
———————————————————–
class CSVReader
{
String hello(TestCaseNumber)
{
def filePath = “C:\\SRTemp\\abc.txt”
File file = new File(filePath)
def line, result;
file.withReader { reader ->
while ((line = reader.readLine()) != null) {
if(line.split(“,”)[0] == TestCaseNumber)
{
result = line;
}
}
}
return result;
}
}
Step 3: set up Preferences -> ReadyAPI (scripts files location to above groovy script location)
————————————————————————————————
Step 4: create a groovy step with following text to read csv file from soapui
——————————————————————————
import Callee
c = new Callee()
//log.info c.hello(“TC004”)
def result = c.hello(“TC004”)
if(result.split(“,”)[0] == “TC004”)
{
log.info(“Hurray!!”)
}else{
log.info(“Hmm….”)
}
Output:
——-
Wed Apr 24 21:03:19 IST 2019:INFO:Hurray!!
0 comments