Forum Discussion

brianb's avatar
brianb
New Contributor
15 years ago

DataSource Loop failing when used with Groovy DataSource

I have a testing scenario in which I have a directory of input and corresponding expected result files. The files are named with the following convention.

Test1-INPUT.txt
Test1-RESULT.txt
Test2-INPUT.txt
Test2-RESULT.txt
...

I want to loop through the input files and perform a request using the data in the *INPUT.txt file as an input and then use an Assertion to compare the output of the request with the data in the corresponding *RESULT.txt file.

I've created a Groovy DataSource with two properties, inputdata and result, that returns the data in the *INPUT.txt and corresponding *RESULT.txt files in the appropriate properties. The DataSource works correctly when I run just the DataSource alone. However, in the TestCase that I created, the DataSource Loop test step is failing with the following error:

TestCase failed [Cancelling due to failed test step:groovy.lang.MissingPropertyException: No such property: currentRow for class: com.eviware.soapui.impl.wsdl.teststeps.WsdlDataSourceLoopTestStep], time taken = 848

Am I not doing something correctly in the Groovy DataSource? Can this type of test case be performed without a Groovy DataSource? I've tried using two seperate Directory DataSources but I could not figure out how to get the two to loop through the files correctly.
  • brianb's avatar
    brianb
    New Contributor
    Sure, here is the code for the DataSource.

    def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context)
    def projectPath = groovyUtils.projectPath

    def dirName = projectPath + "/TestData"

    def row = context.currentStep.currentRow
    def allFiles = []

    new File(dirName).eachFile() { file ->
    if( file.name =~ /INPUT.txt/)
    {
    allFiles.add(file.name)
    }
    }

    if ( (row + 1) <= allFiles.size ) {
    result["inputdata"] = new File(dirName + "/" + allFiles[row]).text
    def resultFile = allFiles[row].replace("INPUT", "RESULT")
    result["resultdata"] = new File(dirName + "/" + resultFile).text
    }
  • Hello!

    Without getting too technical, it's actually the DataSource Loop that retrieves the new data from the DataSource. Because of this, context.currentStep will refer to DataSource Loop if you run the whole TestCase. Please try using this more static way to get a certain Test Step instead:
    def row = testRunner.testCase.testSteps["DataSource"].currentRow

    Hope it works for you!

    /Henrik
    eviware.com