How to read data from text file in SoapUI. SoapUI Pro has some advance feature which is not in SaopUI as data fetching from external sources so in SoapUI we use Groovy script for that. Following are the peace of groovy script code for reading data from text file.
1. Reading all data from text file.
1. Reading all data from text file.
//reading all txt file at once
File file = new File("E://TestData.txt")
fileContent = file.getText()
log.info fileContent
2. Reading data line by line from text file.
//reading text line by line
File file1 = new File("E://TestData.txt")
List textLine = file1.readLines()
log.info textLine
3. Reading data randomly of any line from text file.
//reading text randon line number
File file2 = new File("E://TestData.txt")
List textLine2 = file2.readLines()
rowIndex = Math.abs(new Random().nextInt() % 4 + 1)
log.info textLine2[rowIndex]
Comments
Post a Comment