Hi,
I think I am missing something here:
I am using custom keywords to reuse code for handling lists and tables in our application.
The code works, however when I use the keyword I always get a nullpointer and it fails the cucumberstep in the log:
(*But the code actually works even when the nullpointer is thrown - the main issue is that the step fails *)
Reason:
java.lang.NullPointerException: Cannot invoke method call() on null object
at kalliope.KAL_POST.openFirstPoststukinTable(KAL_POST.groovy:127)
at ✽.I open the first 'poststuk' in the list and verify case acces(C:/Users/knightrider/Katalon Studio/abbKatalonStudio/Include/features/Kalliope/KAL_POST.feature:149)
Since the console did not show exactly where in the keyword the nullpointer was thrown, I decided to copy the code directly into my cucumber step to see if I could debug that way.
Strangely enough the nullpointer is gone when not using the keyword to handle the list and the cucumber step is passed, the only difference I see is in the console.
This is the code in question:, which is copied directly from the keyword into the cucumberstep.
//listHandler.clickFirstCaseInList()()
wait.forKALLoader()
WebDriver driver = DriverFactory.getWebDriver()
WaitForPageLoadKeyword
List<WebElement> tables = driver.findElements(By.id('searchResultsGrid'))
WebElement searchResultsGrid = tables.get(tables.size()-1)
WebElement Table = searchResultsGrid.findElement(By.tagName('tbody'))
List<WebElement> Rows = Table.findElements(By.tagName('tr'))
List<WebElement> Cells = Rows.get(0).findElements(By.tagName('td'))
WebElement FileName = null
WebElement x = null
for(int i=0; i<Cells.size(); i++) {
try {
x = Cells.get(i).findElement(By.className('case'))
if(x != null) {
FileName = x
break
} else {
println 'element is not found'
}
} catch (e) {
//e.printStackTrace()
}
}
wait.andClick(WebUI.convertWebElementToTestObject(FileName), 5)
I could just use the code as is, but that kind of defeates the use of the cutstom keywords.
Hopefully I can learn something here.