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-rows-fetched-in-data-source/m-p/178520/highlight/true#M40637):
DSrowCount = testRunner.testCase.testSteps["DataSource"].rowCount log.info DSrowCount
But this doesn't seem to work, because it returns 1 when there are actually 4 rows. It seems to count only the current row in the DataSource loop. Is there a way to always get the exact number of rows from my Excel file?
Am I doing something wrong?
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.