Forum Discussion

krabhishek_30's avatar
Occasional Contributor
6 years ago

Not able to retrieve the last value in grid data source

I have a very unusal problem.

This is the structure of my test cases :

- grid data source, with 2 columns - dataTag and runDataTag

     - dataTag has the actual data tag
     - runDataTag has value yes and no - which is used to check if this data tag should be run or not.

- groovy step which checks runDataTag value and redirects to next steps or to the data source loop step.

- API call - simply run the API

- groovy step - this validates the data that the API call step returned.

- data source loop step -source step : grid data source and target step : groovy step which checks runDataTag value 


The problem i am facing is with the last record in the grid data source. Lets say i have 25 records in the grid step (this means that there would be total of 26 rows in this step. "grid.getRowCount();" method returns 26 - I believe this is because ready api adds one row to the end by default).  

Now, if i have set the last record to "No", Ready API runs the last row and does not process it - comes back and processes the blank row (which was added by ready api itself) with last records values. Because of this, my groovy step which validates data fails.

To avoid running the last step i wrote a simple groovy, which when encounters the last row, simply exits the test case.


def dataTags = context.expand( '${DataTags#dataTags}' )
String runDataTag = context.expand( '${DataTags#runDataTag}' ).toString()

def grid = testRunner.testCase.testSteps["DataTags"].dataSource.gridModel
int rows = grid.getRowCount(); "Total rows in grid: "+rows

int currentRowIndex = testRunner.testCase.testSteps['DataTags'].currentRow.toInteger() "currentRowIndex: "+currentRowIndex
	if (currentRowIndex == rows-1 )
		testRunner.cancel( "Data Tag cannot be blank." )
		return null
	else if (runDataTag.toLowerCase().equals("no"))
{ "Data tag \""+dataTags+"\" is not set to be resolved. \n runDataTag value: "+ runDataTag
	testRunner.runTestStepByName("DataSource Loop")
	{ ("Running data tag: "+ dataTags)

The problem now i am facing is, it'll not run the last record at all.

How do i resolve this prob ?

2 Replies

  • Radford's avatar
    Super Contributor

    I might be missing something, but looking at the if statement:


    if (currentRowIndex == rows - 1)
    	testRunner.cancel( "Data Tag cannot be blank." )
    	return null

    Are you not cancelling the test runner every time you hit the last row?



    currentRowIndex is set by the currentRow value where the first row has the value 1.


    Thus you will always cancel on the last genuine row (as you are checking against the getRowCount() minus one).

    • krabhishek_30's avatar
      Occasional Contributor

      Radford Ideally it should be cancelled everytime last row is encountered. But that the issue i am facing, Ready API does not cancel.
      It does run the case, but its not entering this if block.


      Since, Ready API, by default, adds 1 row to the grid, i added "rows - 1" - because i have 25 records, but row count method returns 26 (because of extra row added by Ready API). So when last row is encountered, it should cancel the execution of the test case. I tried with "currentRowIndex == rows" condition as well, in this case, ideally, the case should be cancelled when blank row (row added by ready api) is encountered. But it doesn't cancel it then as well. The case is run with value from "dataTag" column of last row (rows-1).