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.