Web request inside tase case returns null object

Hi.

We have a web service that returns a JSON file. I wish to validate the text in the JSON files.

I set up a Katalon test object for the web request.
I test the request and it returns the correct values.

I wish to verify this web request’s text with this simple test case…

import static com.kms.katalon.core.testobject.ObjectRepository.findTestObject
import com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords as WS

//'Send a SOAP request and returns its response'
def response = WS.sendRequest(findTestObject('PSTD/PSTD-01_01'))

//'Verify converted weight after sending request is correct or not'
WS.verifyElementText(response, 'abcxyz123', '3000')

But I receive this error…

2021-07-26 19:51:09.980 INFO c.k.katalon.core.main.TestCaseExecutor - --------------------
2021-07-26 19:51:09.984 INFO c.k.katalon.core.main.TestCaseExecutor - START Test Cases/Test_JSON
2021-07-26 19:51:10.971 DEBUG testcase.Test_JSON - 1: response = sendRequest(findTestObject(“PSTD/PSTD-01_01”))
> log4j:WARN No appenders could be found for logger (org.apache.http.client.protocol.RequestAddCookies).
> log4j:WARN Please initialize the log4j system properly.
2021-07-26 19:51:12.052 INFO c.k.k.core.webservice.common.HarLogger - HAR: C:\Users\in038\AppData\Local\Temp\Katalon\Test Cases\Test_JSON\20210726_195107\requests\main\0.har
2021-07-26 19:51:12.134 DEBUG testcase.Test_JSON - 2: verifyElementText(response, “abcxyz123”, “3000”)
2021-07-26 19:51:12.224 ERROR c.k.k.core.keyword.internal.KeywordMain - :x: Unable to verify element text (Root cause: java.lang.NullPointerException: Cannot invoke method text() on null object
at Script1.run(Script1.groovy:1)
at com.kms.katalon.core.webservice.helper.WebServiceCommonHelper.parseAndExecuteExpressionForJson(WebServiceCommonHelper.java:181)
at com.kms.katalon.core.webservice.keyword.builtin.VerifyElementTextKeyword$_verifyElementText_closure1.doCall(VerifyElementTextKeyword.groovy:49)
at com.kms.katalon.core.webservice.keyword.builtin.VerifyElementTextKeyword$_verifyElementText_closure1.call(VerifyElementTextKeyword.groovy)
at com.kms.katalon.core.keyword.internal.KeywordMain.runKeyword(KeywordMain.groovy:68)
at com.kms.katalon.core.webservice.keyword.builtin.VerifyElementTextKeyword.verifyElementText(VerifyElementTextKeyword.groovy:45)
at com.kms.katalon.core.webservice.keyword.builtin.VerifyElementTextKeyword.execute(VerifyElementTextKeyword.groovy:40)
at com.kms.katalon.core.keyword.internal.KeywordExecutor.executeKeywordForPlatform(KeywordExecutor.groovy:73)
at com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords.verifyElementText(WSBuiltInKeywords.groovy:253)
at com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords$verifyElementText$0.call(Unknown Source)
at Test_JSON.run(Test_JSON:8)
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:398)
at com.kms.katalon.core.main.TestCaseExecutor.doExecute(TestCaseExecutor.java:389)
at com.kms.katalon.core.main.TestCaseExecutor.processExecutionPhase(TestCaseExecutor.java:368)
at com.kms.katalon.core.main.TestCaseExecutor.accessMainPhase(TestCaseExecutor.java:360)
at com.kms.katalon.core.main.TestCaseExecutor.execute(TestCaseExecutor.java:255)
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 TempTestCase1627343467066.run(TempTestCase1627343467066.groovy:25)
)
2021-07-26 19:51:12.231 ERROR c.k.katalon.core.main.TestCaseExecutor - :x: Test Cases/Test_JSON FAILED.

The web request returns a null object. Why?

I thought perhaps its something to do with log4j. So I install these libraries.
image

And I add the following…

import org.apache.log4j.PropertyConfigurator

Properties log4jProp = new Properties();
log4jProp.setProperty("log4j.rootLogger", "WARN");
PropertyConfigurator.configure(log4jProp);

This solves the issues with log4j. But the main error remains.

Perhaps the issue is the Verification tab in the web request object? It is empty, but I’m not sure what it does.

Ilya

Please try the following:

//'Send a SOAP request and returns its response'
def response = WS.sendRequest(findTestObject('PSTD/PSTD-01_01'))
assert response != null

//'Verify converted weight after sending request is correct or not'
WS.verifyElementText(response, 'resonseText', 'Ok')

This would pass. It would imply that the locator you specified "abcxyx123" is wrong, therefore no element is found, thus null is returned. A call to null.text() would certainly fail.

Log4j has nothing to do with your issue.

1 Like

Thank you. This solved the problem.