Forum Discussion

Akash1's avatar
Akash1
New Contributor
3 years ago

Data source groovy

Hello All,

 

I currently use this groovy script to load data to my data source in Ready Api

 

// To get the output value, use the built-in result map object

def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context)
def projectPath = groovyUtils.projectPath
def directoryName = projectPath + "/testData"
def row = testRunner.testCase.testSteps["DataSource"].currentRow
def allFiles = []
new File( directoryName ).eachFile() { file ->
if( file.name =~ /.txt/ ) {
allFiles.add( file.name ) }
}
if ( (row + 1) <= allFiles.size ) {
// Output to the test step property called inputData
result["email"] = new File( directoryName + "/" + allFiles[row] ).text
}

 

It takes emails from a file and puts it all in one row. To make separate entries, I had to put the emails in different text files. How would I change this script to read data from one text file and separate emails into different rows? Thanks.

 

  • ChrisAdams's avatar
    ChrisAdams
    Champion Level 3

    Hi,

     

    I don't think I'm perfectly clear on what you're asking, so if I have this wrong, say so and i'll delete.

     

    You currently have a bunch of files in a folder.  Your script scans the folder and for each file writes the contents to the data source you are dynamically building.

     

    What you want is not to read lots of files.  Instead, you want to read one file.  And for each email within the file, create a new row in the data source you are dynamically building.

     

    I suppose this depends on how the source file looks.

     

    In the source file, is each email on one separate line?  If so, don't even bother transforming, just use that file as your datasource.

    In the source file, can one email spread over multiple lines?  If so, then you need some way to clearly identify the start of each email, a bit like <CRLF> in a text file.  If you can spot some single magic character that delmits each email in the file, then again, don't bother transforming.

     

    If the method to split emails consists for several chars, e.g. "<email><recpients>", then it's possible.  I would read the file into into a single string and use indexOf to find the start and add each 'chunk' as a row in the datasource.