-1

Create a Test data in the Data Files section, and get the values during the runtime of my test script, below is my code

TestData data = findTestData('Advanced Search')
data.changeSheet('RecordCount')
for (int excelRow : (1..5)) {
    selectQuery0 = data.getValue('Full Text Query', excelRow)
    applicationFullTextQuery.add(selectQuery0)
    selectQuery1 = data.getValue('Db Query', excelRow)
    dbQuery.add(selectQuery1)   
}

from the above one i have hardcoded the row count as 5, its working perfectly

But I need to find out/get the no of rows in the excel sheet and apply the count in that for loop.

Prabu
  • 3,550
  • 9
  • 44
  • 85

2 Answers2

1

Use getRowNumbers() method:

TestData data = findTestData('Advanced Search')
data.changeSheet('RecordCount')
def n = data.getRowNumbers()
for (int excelRow : (1..n)) {
    selectQuery0 = data.getValue('Full Text Query', excelRow)
    applicationFullTextQuery.add(selectQuery0)
    selectQuery1 = data.getValue('Db Query', excelRow)
    dbQuery.add(selectQuery1)   
}
Mate Mrše
  • 7,997
  • 10
  • 40
  • 77
  • Getting null pointer exceptionjava.lang.NullPointerException at com.kms.katalon.core.testdata.reader.SheetPOI.getRowNumbers(SheetPOI.java:296) – Prabu Jul 18 '19 at 08:55
  • Thanks for your help, got the answer and post the answer – Prabu Jul 18 '19 at 13:28
  • @Prabu I've checked your answer. It is basically the same thing as this answer. The SO way of doing things would be to accept this answer, not giving another answer with the same content. – Mate Mrše Jul 23 '19 at 13:40
0
TestData data = findTestData('Advanced Search')

data.changeSheet('RecordCount')

for (int excelRow : (1..data.getRowNumbers())) {
    selectQuery0 = data.getValue('Full Text Query', excelRow)

    applicationFullTextQuery.add(selectQuery0)

    selectQuery1 = data.getValue('Db Query', excelRow)

    dbQuery.add(selectQuery1)
}
Prabu
  • 3,550
  • 9
  • 44
  • 85