Forum Discussion

koen_able's avatar
koen_able
Occasional Contributor
5 years ago
Solved

Get total DataSource rows incorrect

I used the following short command to get the total number of rows from the DataSource after reading this community question (https://community.smartbear.com/t5/SoapUI-Pro/how-to-count-the-number-of-...
  • jsheph01's avatar
    jsheph01
    5 years ago

    I started looking into this a little more and figured out a few things. It looks like value of row count does not read directly from the data source. It only looks at how many rows have been read from the datasource for the current iteration. If you were to set the datasource option "Rows Per Iteration" to 2 then your script to get row count will always be 2 (unless there is only one row left).

     

    I was not able to find a method that would get the total row count so I wrote a script to count them all up. I recommend you run this in a script step before your data source.

     

    def tStep = testRunner.testCase.getTestStepByName("DataSource")
    def data = tStep.getDataSource()
    
    //run the datasource test step
    data.prepare(testRunner,context,data.getPreparedProperties() )
    tStep.run(testRunner,context)
    
    //loop through the file until the end is reached
    def cnt = 1
    while(data.isExhausted() == false) {
    	 data.next(testRunner,context,data.getPreparedProperties() )
    	cnt++
    }
    return cnt

    There might be a better way to do this and I would be courious to see if anyone else knows of a simplier way to get the total row count.