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(); log.info "Total rows in grid: "+rows int currentRowIndex = testRunner.testCase.testSteps['DataTags'].currentRow.toInteger() log.info "currentRowIndex: "+currentRowIndex if (currentRowIndex == rows-1 ) { testRunner.cancel( "Data Tag cannot be blank." ) return null } else if (runDataTag.toLowerCase().equals("no")) { log.info "Data tag \""+dataTags+"\" is not set to be resolved. \n runDataTag value: "+ runDataTag testRunner.runTestStepByName("DataSource Loop") } else { log.info ("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 ?