How to verify REST XML Response?

I could able to convert xml response of restful service into JSON response using following method.

  1. Download JSON jar from this page: http://mvnrepository.com/artifact/org.json/json/20140107
  2. Import .jar file into your project: https://docs.katalon.com/display/KD/External+Libraries
  3. Adjust your test case using conversion script to convert XML to JSON. Below is sample script where ‘xmlJSONObj.toString(textIndent)’ is the final result after conversion.

import static com.kms.katalon.core.testobject.ObjectRepository.findTestObject
import org.json.JSONObject as JSONObject
import org.json.XML as XML
import com.kms.katalon.core.testobject.ResponseObject
import com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords as WS

ResponseObject response = WS.sendRequest(findTestObject(‘REST_CommentDetails’))
int textIndent = 2
JSONObject xmlJSONObj = XML.toJSONObject(response.getResponseBodyContent())
xmlJSONObj.toString(textIndent)

But when I tried to verify Converted response with database, I am getting following Error.Please give me some suggestion on this problem.

groovy.lang.MissingMethodException: No signature of method: static com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords.verifyElementPropertyValue() is applicable for argument types: (java.lang.String, java.lang.String, java.lang.String) values.

The error means that the parameters passed into the function is not correct. you need to double check on this issue.

In the above method converted response is storing in ‘’ xmlJSONObj.toString(textIndent)’. and I am assigning that into a variable of the type Object called response and using it for verification as below.

Object response = xmlJSONObj.toString(textIndent)

WS.verifyElementPropertyValue(response, ‘response.data.id’, ‘*****’)

Is this way is correct?

You are using XML class so you need to ensure that the function in use is correct.
If you use Katalon Studio, you can follow the instruction at https://docs.katalon.com/katalon-studio/tutorials/verify-api-responses.html#verifying-soap-response-in-xml-format to verify the response properties.

Above link explains verifying REST response in JSON format and SOAP response in XML format.
But what I need is Verifying REST response in XML format.

XML format you have the same verification. Did you try and it did not work?

Yes I tried.it failed to identify values from the response.

could you take the screenshot of the script and the error message?

This is the code snippet i am using for verification.
where response will contain the response in xml format.****** will be the value fetched from database.and the ‘datalist.data[0].id’ is the xml path of a id from the response.

WS.verifyElementPropertyValue(response, ‘datalist.data[0].id’, ‘*****’)

Error message is:
Reason:
com.kms.katalon.core.exception.StepFailedException: Unable to verify element property value (Root cause: com.kms.katalon.core.exception.StepFailedException: Expected element property value ‘*****’ is not equal with actual property value ’ ')
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)

This method is used to verify JSON, you could use WS.verifyElementText for XML

Error message for the above statement.

Unable to verify element text (Root cause: com.kms.katalon.core.exception.StepFailedException: Expected text is ‘******’ but actual element text is: )

response value fetched is ’ ’ (empty). Katalon failing to fetch the value from XML response…

Because of this only i converted XML response into JSON and tried to verify with json values.

Object response = xmlJSONObj.toString(textIndent)

WS.verifyElementPropertyValue(response, ‘response.data.id’, ‘*****’)

and getting this error:

groovy.lang.MissingMethodException: No signature of method: static com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords.verifyElementPropertyValue() is applicable for argument types: (java.lang.String, java.lang.String, java.lang.String) values.

There is no real benefit to convert the XML response in Json.
Just extract whatever you need from it using XMLSlurper (or Parser), see:
http://groovy-lang.org/processing-xml.html