verifyElementPropertyValue() always returns Null Pointer exception

I have been trying to verify the element property, but the code always runs into an error. Please find the details below :

Code :

response = WS.sendRequest(findTestObject(‘POST/PostRequest’))

println(response.getResponseText())

WS.verifyResponseStatusCode(response, 200)

WS.verifyElementPropertyValue(response, ‘ctx.dev’, ‘wscott’)

Response:

{

“text”: "

Basically,testing to make sure that individuals have access to all: Hardware, Software, Web pages, Web applications and tools. ",

“ctx”: {

“id”: “37fe”,

“system”: {

“initialized”: true,

“dialog_turn_counter”: 1,

“dialog_request_counter”: 1,

“branch_exited”: true,

“branch_exited_reason”: “completed”

},

“dev”: “wscott”,

“voice”: true,

“example”: null

},

“info”: true,

“paraphraseFlag”: false,

“disAffirmFlag”: false,

“status”: “ok”

}

Error :
Test Cases/POST/TC_01_VerifyResponse FAILED because (of) Unable to verify element property value (Root cause: java.lang.NullPointerException)

In the response, I could see you have ‘ctx’ and ‘dev’ property, but you do not have ‘ctx.dev’ property.

You have now:

WS.verifyElementPropertyValue(response, 'ctx.dev', 'wscott')

Possibly you should change it to:

WS.verifyElementPropertyValue(response, 'dev', 'wscott')
1 Like

kazurayam said:

In the response, I could see you have ‘ctx’ and ‘dev’ property, but you do not have ‘ctx.dev’ property.

You have now:

WS.verifyElementPropertyValue(response, 'ctx.dev', 'wscott')

Possibly you should change it to:

WS.verifyElementPropertyValue(response, 'dev', 'wscott')

“ctx”:
{

  "id": "37fe",

  "system": {"initialized": true,"dialog\_turn\_counter": 1,"dialog\_request\_counter": 1,"branch\_exited": true,"branch\_exited_reason": "completed"},


 "dev": "wscott",

 "voice": true,

 "example": null

}

‘dev’ is element of ‘ctx’ and therefore i have used ‘ctx.dev’.

Ah, yes. Now I see you have ‘ctx.dev’

Shivraj Tapkir said:

I have been trying to verify the element property, but the code always runs into an error. Please find the details below :

Code :

response = WS.sendRequest(findTestObject(‘POST/PostRequest’))

println(response.getResponseText())

WS.verifyResponseStatusCode(response, 200)

WS.verifyElementPropertyValue(response, ‘ctx.dev’, ‘wscott’)

Response:

{

“text”: "

Basically,testing to make sure that individuals have access to all: Hardware, Software, Web pages, Web applications and tools. ",

“ctx”: {

“id”: “37fe”,

“system”: {

“initialized”: true,

“dialog_turn_counter”: 1,

“dialog_request_counter”: 1,

“branch_exited”: true,

“branch_exited_reason”: “completed”

},

“dev”: “wscott”,

“voice”: true,

“example”: null

},

“info”: true,

“paraphraseFlag”: false,

“disAffirmFlag”: false,

“status”: “ok”

}

Error :
Test Cases/POST/TC_01_VerifyResponse FAILED because (of) Unable to verify element property value (Root cause: java.lang.NullPointerException)

Hi try below code, I think It will work

response = WS.sendRequest(findTestObject(’‘POST/PostRequest’))

WS.verifyResponseStatusCode(response, 200)

WS.verifyElementPropertyValue(response, ‘ctx.dev’, ‘wscott’)

def slurper = new groovy.json.JsonSlurper()

def result = slurper.parseText(response.getResponseBodyContent())

def dev= result.dev

println(dev)

Shivraj,

Is it possible for you to share the URL of your Application Under Test and you Test Object ‘POST/PostRequest’ detail? so that I can reproduce your problem on my side.

Siva said:

Shivraj Tapkir said:

I have been trying to verify the element property, but the code always runs into an error. Please find the details below :

Code :

response = WS.sendRequest(findTestObject(‘POST/PostRequest’))

println(response.getResponseText())

WS.verifyResponseStatusCode(response, 200)

WS.verifyElementPropertyValue(response, ‘ctx.dev’, ‘wscott’)

Response:

{

“text”: "

Basically,testing to make sure that individuals have access to all: Hardware, Software, Web pages, Web applications and tools. ",

“ctx”: {

“id”: “37fe”,

“system”: {

“initialized”: true,

“dialog_turn_counter”: 1,

“dialog_request_counter”: 1,

“branch_exited”: true,

“branch_exited_reason”: “completed”

},

“dev”: “wscott”,

“voice”: true,

“example”: null

},

“info”: true,

“paraphraseFlag”: false,

“disAffirmFlag”: false,

“status”: “ok”

}

Error :
Test Cases/POST/TC_01_VerifyResponse FAILED because (of) Unable to verify element property value (Root cause: java.lang.NullPointerException)

Hi try below code, I think It will work

response = WS.sendRequest(findTestObject(’‘POST/PostRequest’))

WS.verifyResponseStatusCode(response, 200)

WS.verifyElementPropertyValue(response, ‘ctx.dev’, ‘wscott’)

def slurper = new groovy.json.JsonSlurper()

def result = slurper.parseText(response.getResponseBodyContent())

def dev= result.dev

println(dev)

Updated code:

slurper = new groovy.json.JsonSlurper()

result = slurper.parseText(response.getResponseBodyContent())

ctx= result.ctx

dev = ctx.dev

println(dev) //It Prints wscott on the console.

But when I try to verify element property using the below command :

WS.verifyElementPropertyValue(response, ‘dev’, ‘wscott’) or
WS.verifyElementPropertyValue(response, dev, ‘wscott’)

It again gives me a null pointer exception.

Please try:

WS.verifyElementPropertyValue(response, 'ctx.dev', 'wscott')

kazurayam said:

Please try:

WS.verifyElementPropertyValue(response, 'ctx.dev', 'wscott')

It doesn’t work either. Pasting the console log :

11-30-2018 01:41:38 PM - [END] - End action : Statement - println(response.getResponseText())

11-30-2018 01:41:38 PM - [START] - Start action : verifyResponseStatusCode

11-30-2018 01:41:38 PM - [FAILED] - Unable to verify element property value (Root cause: java.lang.NullPointerException)

11-30-2018 01:41:38 PM - [FAILED] - Test Cases/POST/TC_01_VerifyResponse FAILED because (of) (Stack trace: com.kms.katalon.core.exception.StepFailedException: Unable to verify element property value (Root cause: java.lang.NullPointerException)

at com.kms.katalon.core.keyword.internal.KeywordMain.stepFailed(KeywordMain.groovy:36)

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$1.call(Unknown Source)

at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)

at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)

at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:141)

at Script1543223556650.run(Script1543223556650.groovy:36)

at com.kms.katalon.core.main.ScriptEngine.run(ScriptEngine.java:183)

at com.kms.katalon.core.main.ScriptEngine.runScriptAsRawText(ScriptEngine.java:108)

at com.kms.katalon.core.main.TestCaseExecutor.runScript(TestCaseExecutor.java:294)

at com.kms.katalon.core.main.TestCaseExecutor.doExecute(TestCaseExecutor.java:285)

at com.kms.katalon.core.main.TestCaseExecutor.processExecutionPhase(TestCaseExecutor.java:264)

at com.kms.katalon.core.main.TestCaseExecutor.accessMainPhase(TestCaseExecutor.java:256)

at com.kms.katalon.core.main.TestCaseExecutor.execute(TestCaseExecutor.java:200)

at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:99)

at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:90)

at com.kms.katalon.core.main.TestCaseMain$runTestCase$0.call(Unknown Source)

at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)

at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)

at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:149)

at TempTestCase1543565485036.run(TempTestCase1543565485036.groovy:22)

at groovy.lang.GroovyShell.runScriptOrMainOrTestOrRunnable(GroovyShell.java:263)

at groovy.lang.GroovyShell.run(GroovyShell.java:518)

at groovy.lang.GroovyShell.run(GroovyShell.java:507)

at groovy.ui.GroovyMain.processOnce(GroovyMain.java:653)

at groovy.ui.GroovyMain.run(GroovyMain.java:384)

at groovy.ui.GroovyMain.process(GroovyMain.java:370)

at groovy.ui.GroovyMain.processArgs(GroovyMain.java:129)

at groovy.ui.GroovyMain.main(GroovyMain.java:109)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

at java.lang.reflect.Method.invoke(Method.java:498)

at org.codehaus.groovy.tools.GroovyStarter.rootLoader(GroovyStarter.java:109)

at org.codehaus.groovy.tools.GroovyStarter.main(GroovyStarter.java:131)

)

11-30-2018 01:41:38 PM - [INFO] - Checking response object

11-30-2018 01:41:38 PM - [PASSED] - Verify response status code successfully

11-30-2018 01:41:38 PM - [END] - End action : verifyResponseStatusCode

11-30-2018 01:41:38 PM - [START] - Start action : Statement - slurper = new groovy.json.JsonSlurper()

11-30-2018 01:41:38 PM - [END] - End action : Statement - slurper = new groovy.json.JsonSlurper()

11-30-2018 01:41:38 PM - [START] - Start action : Statement - result = slurper.parseText(response.getResponseBodyContent())

11-30-2018 01:41:38 PM - [END] - End action : Statement - result = slurper.parseText(response.getResponseBodyContent())

11-30-2018 01:41:38 PM - [START] - Start action : Statement - ctx = ctx

11-30-2018 01:41:38 PM - [END] - End action : Statement - ctx = ctx

11-30-2018 01:41:38 PM - [START] - Start action : Statement - dev = dev

11-30-2018 01:41:38 PM - [END] - End action : Statement - dev = dev

11-30-2018 01:41:38 PM - [START] - Start action : Statement - println(dev)

wscott

11-30-2018 01:41:38 PM - [END] - End action : Statement - println(dev)

11-30-2018 01:41:38 PM - [START] - Start action : verifyElementPropertyValue

11-30-2018 01:41:38 PM - [INFO] - Checking response object

11-30-2018 01:41:38 PM - [END] - End action : verifyElementPropertyValue

11-30-2018 01:41:38 PM - [END] - End Test Case : Test Cases/POST/TC_01_VerifyResponse

Please insert the following line into your test case and tell me what you get:

response = WS.sendRequest(findTestObject(''POST/PostRequest'))WS.verifyResponseStatusCode(response, 200)System.out.println("response.isXmlContentType()=" + response.isXmlContentType())


kazurayam said:

Please insert the following line into your test case and tell me what you get:

response = WS.sendRequest(findTestObject(''POST/PostRequest'))WS.verifyResponseStatusCode(response, 200)System.out.println("response.isXmlContentType()=" + response.isXmlContentType())

  

  

11-30-2018 01:56:24 PM - [START] - Start action : Statement - println(“response.isXmlContentType()=” + response.isXmlContentType())

11-30-2018 01:56:24 PM - [END] - End action : Statement - println(“response.isXmlContentType()=” + response.isXmlContentType())

11-30-2018 01:56:24 PM - [END] - End Test Case : Test Cases/POST/TC_01_VerifyResponse

11-30-2018 01:56:24 PM - [ERROR] - Test Cases/POST/TC_01_VerifyResponse FAILED because (of) (Stack trace: java.lang.NullPointerException

at com.kms.katalon.core.testobject.ResponseObject.isXmlContentType(ResponseObject.java:151)

at com.kms.katalon.core.testobject.ResponseObject$isXmlContentType$0.call(Unknown Source)

at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)

at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)

at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:117)

at Script1543223556650.run(Script1543223556650.groovy:28)

at com.kms.katalon.core.main.ScriptEngine.run(ScriptEngine.java:183)

at com.kms.katalon.core.main.ScriptEngine.runScriptAsRawText(ScriptEngine.java:108)

at com.kms.katalon.core.main.TestCaseExecutor.runScript(TestCaseExecutor.java:294)

at com.kms.katalon.core.main.TestCaseExecutor.doExecute(TestCaseExecutor.java:285)

at com.kms.katalon.core.main.TestCaseExecutor.processExecutionPhase(TestCaseExecutor.java:264)

at com.kms.katalon.core.main.TestCaseExecutor.accessMainPhase(TestCaseExecutor.java:256)

at com.kms.katalon.core.main.TestCaseExecutor.execute(TestCaseExecutor.java:200)

at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:99)

at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:90)

at com.kms.katalon.core.main.TestCaseMain$runTestCase$0.call(Unknown Source)

at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)

at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)

at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:149)

at TempTestCase1543566367107.run(TempTestCase1543566367107.groovy:22)

at groovy.lang.GroovyShell.runScriptOrMainOrTestOrRunnable(GroovyShell.java:263)

at groovy.lang.GroovyShell.run(GroovyShell.java:518)

at groovy.lang.GroovyShell.run(GroovyShell.java:507)

at groovy.ui.GroovyMain.processOnce(GroovyMain.java:653)

at groovy.ui.GroovyMain.run(GroovyMain.java:384)

at groovy.ui.GroovyMain.process(GroovyMain.java:370)

at groovy.ui.GroovyMain.processArgs(GroovyMain.java:129)

at groovy.ui.GroovyMain.main(GroovyMain.java:109)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

at java.lang.reflect.Method.invoke(Method.java:498)

at org.codehaus.groovy.tools.GroovyStarter.rootLoader(GroovyStarter.java:109)

at org.codehaus.groovy.tools.GroovyStarter.main(GroovyStarter.java:131)

)

wrong:

response = WS.sendRequest(findTestObject(''POST/PostRequest'))

you should not have 2 consecutive single quotes ‘’ before POST.

please change to:

response = WS.sendRequest(findTestObject('POST/PostRequest'))assert response != null

and try again, please

Shivraj Tapkir said:

kazurayam said:

Please insert the following line into your test case and tell me what you get:

response = WS.sendRequest(findTestObject(''POST/PostRequest'))WS.verifyResponseStatusCode(response, 200)System.out.println("response.isXmlContentType()=" + response.isXmlContentType())

  

  

11-30-2018 01:56:24 PM - [START] - Start action : Statement - println(“response.isXmlContentType()=” + response.isXmlContentType())

11-30-2018 01:56:24 PM - [END] - End action : Statement - println(“response.isXmlContentType()=” + response.isXmlContentType())

11-30-2018 01:56:24 PM - [END] - End Test Case : Test Cases/POST/TC_01_VerifyResponse

11-30-2018 01:56:24 PM - [ERROR] - Test Cases/POST/TC_01_VerifyResponse FAILED because (of) (Stack trace: java.lang.NullPointerException

at com.kms.katalon.core.testobject.ResponseObject.isXmlContentType(ResponseObject.java:151)

at com.kms.katalon.core.testobject.ResponseObject$isXmlContentType$0.call(Unknown Source)

at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)

at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)

at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:117)

at Script1543223556650.run(Script1543223556650.groovy:28)

at com.kms.katalon.core.main.ScriptEngine.run(ScriptEngine.java:183)

at com.kms.katalon.core.main.ScriptEngine.runScriptAsRawText(ScriptEngine.java:108)

at com.kms.katalon.core.main.TestCaseExecutor.runScript(TestCaseExecutor.java:294)

at com.kms.katalon.core.main.TestCaseExecutor.doExecute(TestCaseExecutor.java:285)

at com.kms.katalon.core.main.TestCaseExecutor.processExecutionPhase(TestCaseExecutor.java:264)

at com.kms.katalon.core.main.TestCaseExecutor.accessMainPhase(TestCaseExecutor.java:256)

at com.kms.katalon.core.main.TestCaseExecutor.execute(TestCaseExecutor.java:200)

at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:99)

at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:90)

at com.kms.katalon.core.main.TestCaseMain$runTestCase$0.call(Unknown Source)

at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)

at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)

at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:149)

at TempTestCase1543566367107.run(TempTestCase1543566367107.groovy:22)

at groovy.lang.GroovyShell.runScriptOrMainOrTestOrRunnable(GroovyShell.java:263)

at groovy.lang.GroovyShell.run(GroovyShell.java:518)

at groovy.lang.GroovyShell.run(GroovyShell.java:507)

at groovy.ui.GroovyMain.processOnce(GroovyMain.java:653)

at groovy.ui.GroovyMain.run(GroovyMain.java:384)

at groovy.ui.GroovyMain.process(GroovyMain.java:370)

at groovy.ui.GroovyMain.processArgs(GroovyMain.java:129)

at groovy.ui.GroovyMain.main(GroovyMain.java:109)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

at java.lang.reflect.Method.invoke(Method.java:498)

at org.codehaus.groovy.tools.GroovyStarter.rootLoader(GroovyStarter.java:109)

at org.codehaus.groovy.tools.GroovyStarter.main(GroovyStarter.java:131)

)

the error message is same.

please change to:

response = WS.sendRequest(findTestObject('POST/PostRequest'))assert response != null

and try again, please

kazurayam said:

please change to:

response = WS.sendRequest(findTestObject('POST/PostRequest'))assert response != null

and try again, please

there is no error message for this. But for response.isXmlContentType()

there is no error message for this.

Then, how the following line worked?

WS.verifyElementPropertyValue(response, 'ctx.dev', 'wscott')

kazurayam said:

there is no error message for this.

Then, how the following line worked?

WS.verifyElementPropertyValue(response, 'ctx.dev', 'wscott')

The code passes for

response = WS.sendRequest(findTestObject(‘POST/PostRequest’))

assert response != null

But it fails for

println(“response.isXmlContentType()=” + response.isXmlContentType())

and
WS.verifyElementPropertyValue(response, ‘ctx.dev’, ‘wscott’)

Is there something wrong with the locator ‘ctx.dev’ , because when we parse and try to print ‘ctx.dev’ , it returns ‘wscott’. i.e.

slurper = new groovy.json.JsonSlurper()

result = slurper.parseText(response.getResponseBodyContent())

ctx= result.ctx

dev = ctx.dev

println(dev) // It prints wscott

But it fails for
println(“response.isXmlContentType()=” + response.isXmlContentType())

What do you mean “it fails for”? Do you get NullPointerException? or Do you see true or false is printed?

Please try to print the content type of ResponseObject as follows:

response = WS.sendRequest(findTestObject('POST/PostRequest'))assert response != nullprintln("content type=" + response.getContentType())

What do you get by response.getContentType()?

kazurayam said:

Please try to print the content type of ResponseObject as follows:

response = WS.sendRequest(findTestObject('POST/PostRequest'))assert response != nullprintln("content type=" + response.getContentType())

What do you get by response.getContentType()?

content type=null