Forum Discussion

Akash1's avatar
Akash1
New Contributor
3 years ago

Ready API datasource with groovy error

Hello All,

 

I am having the following error when I run this groovy script for my datasource in readyapi: Error in datasource script of Data source. Cannot get property of "current row" on null 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
}

 

Could someone please help me with this. Thanks.

  • Hi,

     

    Just focusing on the error message initially....

     

    Your line def row = testRunner.testCase.testSteps["DataSource"].currentRow should work.  It works for me, but only after I checked that the bit in speech marks is correct.  E.g. is your datasource step definitely called DataSource.  Also, is your Groovy step after the Datasouce step and within the datasource loop?

  • ChrisAdams's avatar
    ChrisAdams
    Champion Level 3

    Hi,

     

    Just focusing on the error message initially....

     

    Your line def row = testRunner.testCase.testSteps["DataSource"].currentRow should work.  It works for me, but only after I checked that the bit in speech marks is correct.  E.g. is your datasource step definitely called DataSource.  Also, is your Groovy step after the Datasouce step and within the datasource loop?

    • Akash1's avatar
      Akash1
      New Contributor

      You're right. Mine was called "Data Source", not "DataSource". It works now after that edit. Thank you!