Getting java.lang.NullPointerException when using TestData.getValue

I’m trying to use getValue method defined in com.kms.katalon.core.testdata.DBData to get data using column name but i’m getting a null pointer exception

i’m able to use the column number version but not by name version

Reason:
java.lang.NullPointerException
at com.kms.katalon.core.testdata.DBData.verifyColumnName(DBData.java:110)
at com.kms.katalon.core.testdata.AbstractTestData.getObjectValue(AbstractTestData.java:131)
at com.kms.katalon.core.testdata.AbstractTestData.getValue(AbstractTestData.java:102)
at com.kms.katalon.core.testdata.TestData$getValue$0.call(Unknown Source)
at mypackage.Utilities.GetDroitsUser(Utilities.groovy:91)
at mypackage.Utilities.invokeMethod(Utilities.groovy)
at com.kms.katalon.core.main.CustomKeywordDelegatingMetaClass.invokeStaticMethod(CustomKeywordDelegatingMetaClass.java:50)
at Command 120.run(Command 120:56)
at com.kms.katalon.core.main.ScriptEngine.run(ScriptEngine.java:194)
at com.kms.katalon.core.main.ScriptEngine.runScriptAsRawText(ScriptEngine.java:119)
at com.kms.katalon.core.main.TestCaseExecutor.runScript(TestCaseExecutor.java:337)
at com.kms.katalon.core.main.TestCaseExecutor.doExecute(TestCaseExecutor.java:328)
at com.kms.katalon.core.main.TestCaseExecutor.processExecutionPhase(TestCaseExecutor.java:307)
at com.kms.katalon.core.main.TestCaseExecutor.accessMainPhase(TestCaseExecutor.java:299)
at com.kms.katalon.core.main.TestCaseExecutor.execute(TestCaseExecutor.java:233)
at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:114)
at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:105)
at com.kms.katalon.core.main.TestCaseMain$runTestCase$0.call(Unknown Source)
at TempTestCase1562166893097.run(TempTestCase1562166893097.groovy:21)

method is defined inside mypackage.Utilities class

@Keyword
def String GetDroitsUser(String username) {

def PrinterAccess = findTestData(‘Data Files/Impriments/DroitsImprUsers’);
println PrinterAccess.getValue(“id_user”, 1)

}

when i use getColumnNames() methode i get this

[nom_ut, id_user, idimprimante, name]

so the column name is correct

this is the api reference
https://api-docs.katalon.com/com/kms/katalon/core/testdata/DBData.html

i’m using katalon v 6.2.1b2

2 Likes

No one has information about this issue ?

1 Like

For anyone having the same issue here is a workaround until the issue is resolved

static String getValue(TestData dataFile,String columnName,int rowNumber){

	ArrayList<String> table = dataFile.getColumnNames()

	def index = table.indexOf(columnName)

	return dataFile.getValue(index+1, rowNumber)

}
2 Likes

@ThanhTo Please follow this issue

1 Like

not sure about your solution.
how can i modify my current codes? i have issue about column name cannot be use (null pointer exceptional). i need to use column index instead of name (itemid, flag).

//get data from Data Files
TestData data = findTestData(‘Data Files/Database’)

for(i=1; i<= data.getRowNumbers(); i++){
if(data.getValue(‘itemid’, i) == ‘123’){
println data.getValue(‘flag’, i)
assert data.getValue(‘flag’, i) == ‘true’
KeywordUtil.markPassed(“test passed”)
}
}

1 Like

Hello ,
the method that i wrote is static which means you have to give it all the data manually (you can lookup the definition of static objects in java).
You have to use it like this : getValue(“Your test data”,“your column name”,“the rowNumber”);

so do this:

//get data from Data Files
TestData data = findTestData(‘Data Files/Database’)
for(i=1; i<= data.getRowNumbers(); i++){

if(data.getValue(‘itemid’, i) == ‘123’){

println getValue(data,‘flag’, i)
assert data.getValue(data,‘flag’, i) == ‘true’
KeywordUtil.markPassed(“test passed”)
}
}

it’s not perfect but until the api is fixed this is the best way

1 Like

It’s definitely a bug with the Data Files of Data Type = Database Data (Internal Data does not have this issue).

Another temporary workaround (until fixed) is:

TestData data = findTestData(‘Data Files/DBdata’);

println(data.getColumnNames()); /* Prints: [accountid, url] */

for(int i = 1; i <= data.getRowNumbers(); i ++) {
String columnA= data.getValue(data.getColumnNames().toString().indexOf(‘accountid’), i);
println(columnA);
}

2 Likes

Hi everyone,

We have fixed this problem with using getValue on Database Test Data and we will release the fix soon. Thanks !

1 Like

Hi everyone, we released 7.0.5 which resolved this issue, please try it out. Thank you all for reporting.

1 Like

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.