Unable to verify element property value

Hi,

The data driven test is failing due to “Unable to verify element property value (Root cause: java.lang.NullPointerException: Cannot invoke method getAt() on null object)”. Couldn’t identify where am I going wrong, any thoughts please ?

For reference, I was following the video below to create the data driven testing.

Here is my test case -
Test Case :

import static com.kms.katalon.core.checkpoint.CheckpointFactory.findCheckpoint
import static com.kms.katalon.core.testcase.TestCaseFactory.findTestCase
import static com.kms.katalon.core.testdata.TestDataFactory.findTestData
import static com.kms.katalon.core.testobject.ObjectRepository.findTestObject
import com.kms.katalon.core.checkpoint.Checkpoint as Checkpoint
import com.kms.katalon.core.cucumber.keyword.CucumberBuiltinKeywords as CucumberKW
import com.kms.katalon.core.mobile.keyword.MobileBuiltInKeywords as Mobile
import com.kms.katalon.core.model.FailureHandling as FailureHandling
import com.kms.katalon.core.testcase.TestCase as TestCase
import com.kms.katalon.core.testdata.TestData as TestData
import com.kms.katalon.core.testobject.TestObject as TestObject
import com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords as WS
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI
import internal.GlobalVariable as GlobalVariable

println('Url : ’ + url)

println('Category : ’ + category)

response = WS.sendRequest(findTestObject(‘POST-UrlGetInfoCopy’, [(‘url’) : url]))

WS.verifyElementPropertyValue(response, ‘results[0].queries.getinfo.cats[0].catid’, category)

Exception :variablesdefnied

01-11-2019 04:13:21 PM verifyElementPropertyValue(response, “results[0].queries.getinfo.cats[0].catid”, category)

Elapsed time: 0.105s

verifyElementPropertyValue(response, “results[0].queries.getinfo.cats[0].catid”, category) FAILED.
Reason:
com.kms.katalon.core.exception.StepFailedException: Unable to verify element property value (Root cause: java.lang.NullPointerException: Cannot invoke method getAt() on null object)
at com.kms.katalon.core.keyword.internal.KeywordMain.stepFailed(KeywordMain.groovy:32)
at com.kms.katalon.core.keyword.internal.KeywordMain.stepFailed(KeywordMain.groovy)
at com.kms.katalon.core.keyword.internal.KeywordMain.runKeyword(KeywordMain.groovy:56)
at com.kms.katalon.core.webservice.keyword.builtin.VerifyElementPropertyValueKeyword.verifyElementPropertyValue(VerifyElementPropertyValueKeyword.groovy:48)
at com.kms.katalon.core.webservice.keyword.builtin.VerifyElementPropertyValueKeyword.execute(VerifyElementPropertyValueKeyword.groovy:43)
at com.kms.katalon.core.keyword.internal.KeywordExecutor.executeKeywordForPlatform(KeywordExecutor.groovy:53)
at com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords.verifyElementPropertyValue(WSBuiltInKeywords.groovy:123)
at com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords$verifyElementPropertyValue$0.call(Unknown Source)
at CCRefresh-UrlGetInfo.run(CCRefresh-UrlGetInfo:22)
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:328)
at com.kms.katalon.core.main.TestCaseExecutor.doExecute(TestCaseExecutor.java:319)
at com.kms.katalon.core.main.TestCaseExecutor.processExecutionPhase(TestCaseExecutor.java:298)
at com.kms.katalon.core.main.TestCaseExecutor.accessMainPhase(TestCaseExecutor.java:290)
at com.kms.katalon.core.main.TestCaseExecutor.execute(TestCaseExecutor.java:224)
at com.kms.katalon.core.main.TestSuiteExecutor.accessTestCaseMainPhase(TestSuiteExecutor.java:129)
at com.kms.katalon.core.main.TestSuiteExecutor.accessTestSuiteMainPhase(TestSuiteExecutor.java:112)
at com.kms.katalon.core.main.TestSuiteExecutor.execute(TestSuiteExecutor.java:81)
at com.kms.katalon.core.main.TestCaseMain.startTestSuite(TestCaseMain.java:149)
at com.kms.katalon.core.main.TestCaseMain$startTestSuite$0.call(Unknown Source)
at TempTestSuite1547248382454.run(TempTestSuite1547248382454.groovy:36)

Attached is the screen capture for the variables defined for the test case.

I would check to make sure this path to your test object is correct.

I am fetching it as shown in the attachment “PathofTestObject.png”

Please let me know if the test object needs to be corrected.

Please take screenshot of the definition of Object Repository/POST UrlGetInfoCopy and share it.

I have the test case of the Object Repository/POST UrlGetInfoCopy in the original question.


Attached is the same in manual.

Please also find the payload below :–

{“requestid”: “12345”,“oemid”: “cddks”,“deviceid”: “sis-10K”,“uid”: “sis_10”,“urls”: [${url}],“queries”: [“getinfo”],“a1cat”: 1,“reputation”: 1,“xml”: 0}

Any ideas please, how should I overcome this problem ?

Possibly your expression results[0].queries.getinfo.cats[0].catid is wrong against the response body JSON. Most likely either of:

  1. the response does not have any results node
  2. the response does not have any cats node

You should look at the JSON itself. Just insert a print and try:

response = WS.sendRequest(findTestObject(‘POST-UrlGetInfoCopy’, [(‘url’) : url]))
println response.getResponseText()
WS.verifyElementPropertyValue(response, ‘results[0].queries.getinfo.cats[0].catid’, category)

We get the following response for the api call. In this case, how should I build my verification.

{
“status”:200,
“reqid”:“12345”,
“typical”:“url”,
“results”:[
{
“resource”:“google.com”,
“queries”:{
“Inquiry”:{
“a1”:0,
“read”:81,
“lgm”:“google.com”,
“calls”:[
{
“fatid”:50,
“config”:99
}]
}
}
}]
}

What do you see if …

WS.verifyElementPropertyValue(response, ‘queries.getinfo.cats[0].catid’, category)

I am still getting the error -

01-16-2019 11:04:33 AM verifyElementPropertyValue(response, “queries.getinfo.cats[0].catid”, category)

Elapsed time: 0.312s

Unable to verify element property value (Root cause: java.lang.NullPointerException: Cannot get property ‘getinfo’ on null object)
(Root cause: java.lang.NullPointerException: Cannot get property ‘getinfo’ on null object)
at com.kms.katalon.core.keyword.internal.KeywordMain.stepFailed(KeywordMain.groovy:32)
at com.kms.katalon.core.keyword.internal.KeywordMain.stepFailed(KeywordMain.groovy)
at com.kms.katalon.core.keyword.internal.KeywordMain.runKeyword(KeywordMain.groovy:56)
at com.kms.katalon.core.webservice.keyword.builtin.VerifyElementPropertyValueKeyword.verifyElementPropertyValue(VerifyElementPropertyValueKeyword.groovy:48)
at com.kms.katalon.core.webservice.keyword.builtin.VerifyElementPropertyValueKeyword.execute(VerifyElementPropertyValueKeyword.groovy:43)
at com.kms.katalon.core.keyword.internal.KeywordExecutor.executeKeywordForPlatform(KeywordExecutor.groovy:53)
at com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords.verifyElementPropertyValue(WSBuiltInKeywords.groovy:123)
at com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords$verifyElementPropertyValue$0.call(Unknown Source)
at ProofOfConcept.run(ProofOfConcept:19)
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:328)
at com.kms.katalon.core.main.TestCaseExecutor.doExecute(TestCaseExecutor.java:319)
at com.kms.katalon.core.main.TestCaseExecutor.processExecutionPhase(TestCaseExecutor.java:298)
at com.kms.katalon.core.main.TestCaseExecutor.accessMainPhase(TestCaseExecutor.java:290)
at com.kms.katalon.core.main.TestCaseExecutor.execute(TestCaseExecutor.java:224)
at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:106)
at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:97)
at com.kms.katalon.core.main.TestCaseMain$runTestCase$0.call(Unknown Source)
at TempTestCase1547661861376.run(TempTestCase1547661861376.groovy:22)

What do you see if you try this:

println "getContentType: " + response.getContentType()

Does it say?:

getContentType: application/json; charset=utf-8

If not, your AUT is wrong.

If yes, … ???

When I test the test object by itself, it gets the response header as below -

HTTP/1.1 200 OK
Server: Microsoft-IIS/7.5
Cache-Control: private
Access-Control-Allow-Origin: *
Connection: keep-alive
X-AspNet-Version: 4.0.30319
Content-Length: 181
Date: Wed, 16 Jan 2019 17:59:33 GMT
X-Powered-By: ASP.NET
Content-Type: application/json; charset=utf-8

However, If I create the test case and execute it, it is throwing the following error -

01-16-2019 07:11:37 PM Test Cases/ProofOfConcept

01-16-2019 07:11:41 PM println("getContentType: " + response.getContentType())

Elapsed time: 0.160s

println("getContentType: " + response.getContentType()) FAILED.
Reason:
groovy.lang.MissingPropertyException: No such property: response for class: Script1547660508279
at ProofOfConcept.run(ProofOfConcept:17)
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:328)
at com.kms.katalon.core.main.TestCaseExecutor.doExecute(TestCaseExecutor.java:319)
at com.kms.katalon.core.main.TestCaseExecutor.processExecutionPhase(TestCaseExecutor.java:298)
at com.kms.katalon.core.main.TestCaseExecutor.accessMainPhase(TestCaseExecutor.java:290)
at com.kms.katalon.core.main.TestCaseExecutor.execute(TestCaseExecutor.java:224)
at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:106)
at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:97)
at com.kms.katalon.core.main.TestCaseMain$runTestCase$0.call(Unknown Source)
at TempTestCase1547691093050.run(TempTestCase1547691093050.groovy:22)

Please share your testcase.

Please find the test case screen capture -

Here is the code -

import static com.kms.katalon.core.checkpoint.CheckpointFactory.findCheckpoint
import static com.kms.katalon.core.testcase.TestCaseFactory.findTestCase
import static com.kms.katalon.core.testdata.TestDataFactory.findTestData
import static com.kms.katalon.core.testobject.ObjectRepository.findTestObject
import com.kms.katalon.core.checkpoint.Checkpoint as Checkpoint
import com.kms.katalon.core.cucumber.keyword.CucumberBuiltinKeywords as CucumberKW
import com.kms.katalon.core.mobile.keyword.MobileBuiltInKeywords as Mobile
import com.kms.katalon.core.model.FailureHandling as FailureHandling
import com.kms.katalon.core.testcase.TestCase as TestCase
import com.kms.katalon.core.testdata.TestData as TestData
import com.kms.katalon.core.testobject.TestObject as TestObject
import com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords as WS
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI
import internal.GlobalVariable as GlobalVariable

println ("getContentType: " + response.getContentType())

response = WS.sendRequest(findTestObject(‘POST-UrlGetInfoCopy’, [(‘url’) : url]))
println (“url is sent”)

WS.verifyElementPropertyValue(response, [(‘queries.getinfo.cats[0].catid’), category])
println (“category is received.”)

You can not refer to the response variable before you create it. Change the code as follows, and try again.

So sorry about that, I have corrected it and ran the test case. Here is the console log -

SLF4J: The requested version 1.7.16 by your slf4j binding is not compatible with [1.6]
SLF4J: See http://www.slf4j.org/codes.html#version_mismatch for further details.
2019-01-16 19:29:06.908 e[34mINFO e[0;39m e[36mc.k.katalon.core.main.TestCaseExecutor -e[0;39m e[39m--------------------e[0;39m
2019-01-16 19:29:06.917 e[34mINFO e[0;39m e[36mc.k.katalon.core.main.TestCaseExecutor -e[0;39m e[39mSTART Test Cases/ProofOfConcepte[0;39m
2019-01-16 19:29:08.133 e[34mINFO e[0;39m e[36mc.k.katalon.core.main.TestCaseExecutor -e[0;39m e[39m(Default) url = google.come[0;39m
2019-01-16 19:29:08.169 e[34mINFO e[0;39m e[36mc.k.katalon.core.main.TestCaseExecutor -e[0;39m e[39m(Default) category = 50e[0;39m
2019-01-16 19:29:10.818 e[39mDEBUGe[0;39m e[36mtestcase.ProofOfConcept -e[0;39m e[39m1: response = sendRequest(findTestObject(“POST-UrlGetInfoCopy”, [“url”:url]))e[0;39m
2019-01-16 19:29:13.963 e[34mINFO e[0;39m e[36mc.k.k.core.util.BrowserMobProxyManager -e[0;39m e[39mHAR: C:\Users\SPULLA~1\AppData\Local\Temp\Katalon\Test Cases\ProofOfConcept\20190116_192901\requests\main\0.hare[0;39m
2019-01-16 19:29:14.409 e[39mDEBUGe[0;39m e[36mtestcase.ProofOfConcept -e[0;39m e[39m2: println(“url is sent”)e[0;39m
url is sent
2019-01-16 19:29:14.513 e[39mDEBUGe[0;39m e[36mtestcase.ProofOfConcept -e[0;39m e[39m3: println("getContentType: " + response.getContentType())e[0;39m
getContentType: application/json; charset=utf-8
2019-01-16 19:29:14.587 e[39mDEBUGe[0;39m e[36mtestcase.ProofOfConcept -e[0;39m e[39m4: verifyElementPropertyValue(response, [“queries.getinfo.cats[0].catid”, category])e[0;39m
2019-01-16 19:29:14.712 e[1;31mERRORe[0;39m e[36mc.k.katalon.core.main.TestCaseExecutor -e[0;39m e[31m❌ verifyElementPropertyValue(response, [“queries.getinfo.cats[0].catid”, category]) FAILED.e[0;39m
e[31mReason:e[0;39m
e[31mgroovy.lang.MissingMethodException: No signature of method: static com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords.verifyElementPropertyValue() is applicable for argument types: (com.kms.katalon.core.testobject.ResponseObject, java.util.ArrayList) values: [200 3 KB, [queries.getinfo.cats[0].catid, 50]]e[0;39m
e[31mPossible solutions: verifyElementPropertyValue(com.kms.katalon.core.testobject.ResponseObject, java.lang.String, java.lang.Object), verifyElementPropertyValue(com.kms.katalon.core.testobject.ResponseObject, java.lang.String, java.lang.Object, com.kms.katalon.core.model.FailureHandling)e[0;39m
e[31m at ProofOfConcept.run(ProofOfConcept:22)e[0;39m
e[31m at com.kms.katalon.core.main.ScriptEngine.run(ScriptEngine.java:194)e[0;39m
e[31m at com.kms.katalon.core.main.ScriptEngine.runScriptAsRawText(ScriptEngine.java:119)e[0;39m
e[31m at com.kms.katalon.core.main.TestCaseExecutor.runScript(TestCaseExecutor.java:328)e[0;39m
e[31m at com.kms.katalon.core.main.TestCaseExecutor.doExecute(TestCaseExecutor.java:319)e[0;39m
e[31m at com.kms.katalon.core.main.TestCaseExecutor.processExecutionPhase(TestCaseExecutor.java:298)e[0;39m
e[31m at com.kms.katalon.core.main.TestCaseExecutor.accessMainPhase(TestCaseExecutor.java:290)e[0;39m
e[31m at com.kms.katalon.core.main.TestCaseExecutor.execute(TestCaseExecutor.java:224)e[0;39m
e[31m at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:106)e[0;39m
e[31m at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:97)e[0;39m
e[31m at com.kms.katalon.core.main.TestCaseMain$runTestCase$0.call(Unknown Source)e[0;39m
e[31m at TempTestCase1547692141957.run(TempTestCase1547692141957.groovy:22)e[0;39m
2019-01-16 19:29:15.039 e[1;31mERRORe[0;39m e[36mc.k.katalon.core.main.TestCaseExecutor -e[0;39m e[31m❌ Test Cases/ProofOfConcept FAILED.e[0;39m
e[31mReason:e[0;39m
e[31mgroovy.lang.MissingMethodException: No signature of method: static com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords.verifyElementPropertyValue() is applicable for argument types: (com.kms.katalon.core.testobject.ResponseObject, java.util.ArrayList) values: [200 3 KB, [queries.getinfo.cats[0].catid, 50]]e[0;39m
e[31mPossible solutions: verifyElementPropertyValue(com.kms.katalon.core.testobject.ResponseObject, java.lang.String, java.lang.Object), verifyElementPropertyValue(com.kms.katalon.core.testobject.ResponseObject, java.lang.String, java.lang.Object, com.kms.katalon.core.model.FailureHandling)e[0;39m
e[31m at ProofOfConcept.run(ProofOfConcept:22)e[0;39m
e[31m at com.kms.katalon.core.main.ScriptEngine.run(ScriptEngine.java:194)e[0;39m
e[31m at com.kms.katalon.core.main.ScriptEngine.runScriptAsRawText(ScriptEngine.java:119)e[0;39m
e[31m at com.kms.katalon.core.main.TestCaseExecutor.runScript(TestCaseExecutor.java:328)e[0;39m
e[31m at com.kms.katalon.core.main.TestCaseExecutor.doExecute(TestCaseExecutor.java:319)e[0;39m
e[31m at com.kms.katalon.core.main.TestCaseExecutor.processExecutionPhase(TestCaseExecutor.java:298)e[0;39m
e[31m at com.kms.katalon.core.main.TestCaseExecutor.accessMainPhase(TestCaseExecutor.java:290)e[0;39m
e[31m at com.kms.katalon.core.main.TestCaseExecutor.execute(TestCaseExecutor.java:224)e[0;39m
e[31m at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:106)e[0;39m
e[31m at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:97)e[0;39m
e[31m at com.kms.katalon.core.main.TestCaseMain$runTestCase$0.call(Unknown Source)e[0;39m
e[31m at TempTestCase1547692141957.run(TempTestCase1547692141957.groovy:22)e[0;39m
2019-01-16 19:29:15.170 e[34mINFO e[0;39m e[36mc.k.katalon.core.main.TestCaseExecutor -e[0;39m e[39mEND Test Cases/ProofOfConcepte[0;39m

Looks like some weird characters printed with the console log.

The ContetType you received is “application/json; charset=utf-8”; this is OK.

WS.verifyElementPropertyValue(response, [(‘queries.getinfo.cats[0].catid’), category])

Here you are passing an instance of java.util.List as the 2nd param. This is wrong. As document describes, the 2nd and the 3rd argument to the verifyElementPropertyValue should be String.

Change your code as follows and try again:

WS.verifyElementPropertyValue(response, 'queries.getinfo.cats[0].catid', category)

This is a known problem. See