Handle Response Message xml instead of json

Hi all,

I have a problem with WS.verifyElementText.

I try to validate a response in “text/xml; charset=utf-8” format, but it seems to me that Katalon tries to parse it with a json parser instead of xml.

The functionality is documented here:
Handle Response Messages | Katalon Docs

This is the code:

WS.comment('Check if Service Simulator is Empty')
isempty_response = WS.sendRequest(findTestObject('Tools/ServiceSimulator/Recorder/IsEmpty'))
WS.verifyResponseStatusCode(isempty_response, 200, FailureHandling.CONTINUE_ON_FAILURE)

WS.verifyElementText(isempty_response, 'IsEmptyResponse.IsEmptyResult', 'true')

The response looks like this:

Response ContentType: 
text/xml; charset=utf-8

Response Body: 
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"><s:Header><ActivityId CorrelationId="70353019-b5cb-4159-8f09-96494bcafc3e" xmlns="http://schemas.microsoft.com/2004/09/ServiceModel/Diagnostics">00000000-0000-0000-0000-000000000000</ActivityId></s:Header><s:Body><IsEmptyResponse xmlns="http://tempuri.org/"><IsEmptyResult>true</IsEmptyResult></IsEmptyResponse></s:Body></s:Envelope>

This is the error message thrown by Katalon:

08-31-2022 08:43:30 AM verifyElementText(isempty_response, "IsEmptyResponse.IsEmptyResult", "true")

Elapsed time: 0,093s

Unable to verify element text (Root cause: groovy.json.JsonException: Unable to determine the current character, it is not a string, number, array, or object

The current character read is '<' with an int value of 60
Unable to determine the current character, it is not a string, number, array, or object
line number 1
index number 0
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"><s:Header><ActivityId CorrelationId="70353019-b5cb-4159-8f09-96494bcafc3e" xmlns="http://schemas.microsoft.com/2004/09/ServiceModel/Diagnostics">00000000-0000-0000-0000-000000000000</ActivityId></s:Header><s:Body><IsEmptyResponse xmlns="http://tempuri.org/"><IsEmptyResult>true</IsEmptyResult></IsEmptyResponse></s:Body></s:Envelope>
^
	at Script1.run(Script1.groovy:1)
	at com.kms.katalon.core.webservice.helper.WebServiceCommonHelper.parseAndExecuteExpressionForJson(WebServiceCommonHelper.java:212)

Do you know what my mistake is? I thought that Katalon will recognize the response format by response header?

Thank you in advance for your help

greetings
Jan

Can you change your server software?
Can you change the value of ContentType from

text/xml; charset=utf-8

to

text/xml

Then your test in katalon will work.


Why? See katalon-studio-testing-framework/ResponseObject.java at master · katalon-studio/katalon-studio-testing-framework · GitHub

/**
     * Check if the content type of this response is xml
     * 
     * @return true if the content type of this response is xml, otherwise false
     */
    public boolean isXmlContentType() {
        String contentTypeString = contentType.toLowerCase();
        return contentType != null && (
                contentTypeString.startsWith("application/xml")
                || contentTypeString.equals("application/soap+xml") 
                || contentTypeString.equals("text/xml"));
    }

Here you find

contentTypeString.equals("text/xml")

It should rather be

contentTypeString.startsWith("text/xml")

I have no idea why Katalon developer wrote equals("text/xml") rather than startsWith("text/xml")

I think that this is a bug, is an evidence of poor quality of WebService testing feature of Katalon Studio.

@vu.tran

PLS move this to the Bug category.

I’m having the same issue. Would be great to have it fixed.

@vadim.nechunaev

I am afraid this issue is not addressed by Katalon team; Perhaps they are not aware of this stupid bug. Possibly they are not fixing this unless pushed more.

Are you a paying user? If so, please raise an official Support Request as described at
https://katalonsupport.force.com/katalonhelpcenter/s/article/How-to-submit-a-Support-Case

No, i’m not. I only started using Katalon this week actually. One of the first problems i encountered. Well, i solved it with Groovy’s XmlParser. Here’s the code, if you’re interested.

In this i’m using Eval.me() to execute GPath passed as a String to a custom keyword. And so it returns an array list of strings with the search result. Not sure if that’s exactly what i’ll use, but for now it looks good.

	@Keyword
	List<String> getElementsStringArray(String xmlBody, String gpath) {
		List<String> valueList = new ArrayList<>()
		gpath = "XmlText." + gpath

		def responseNodeTree = new XmlSlurper().parseText(xmlBody)
		def nodeList = Eval.me('XmlText', responseNodeTree, gpath)
		nodeList.each({
			valueList.add(it.text())
		})

		return valueList
	}

well done.