How to create VerifyElementText Test Case for MTOM Enabled SOAP Web Services?

Hello,

I have created Web Service Project. Following is the Script of my Test Case, which verifies element text as shown in the documentation:

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

def response = WS.sendRequest(findTestObject(‘ProductById’))
WS.verifyElementText(response, “Product.Reference”, “MyReference”)

When I’m running this test case I’m getting the error: [FAILED] - Unable to verify element text (Root cause: org.xml.sax.SAXParseException: Content is not allowed in prolog.)

Then I have used: com.kms.katalon.core.util.KeywordUtil#logInfo to see the response.responseText, I have received, which was:

–uuid:4e39ea48-6560-46b7-a30c-201dfaf98f51
Content-Type: application/xop+xml; charset=UTF-8; type=“text/xml”;
Content-Transfer-Encoding: binary
Content-ID: <root.message@cxf.apache.org>

<soap:Envelope xmlns:soap=“http://schemas.xmlsoap.org/soap/envelope/”><soap:Body><ns2:getProductResponse xmlns:ns2=“http://mycompany.com/”><Product><Reference>MyReference</Reference></Product></ns2:getProductResponse></soap:Body></soap:Envelope>
–uuid:4e39ea48-6560-46b7-a30c-201dfaf98f51–

The Web Service I am testing MTOM enabled. That’s why the response text is of that format.

How to create test case in this case?

 

Hello Vinh,

Thank you very much. Your solution worked like a charm. I have created a custom keyword for this purpose. Following code might help for the fellow developers:
`package com.mycompany.qa.automcation.keyword

import com.kms.katalon.core.annotation.Keyword
import com.kms.katalon.core.keyword.BuiltinKeywords
import com.kms.katalon.core.model.FailureHandling
import com.kms.katalon.core.testobject.ResponseObject
import com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords

import groovy.transform.CompileStatic

public class WSMtomCustomKeyWords extends BuiltinKeywords {

@CompileStatic
@Keyword(keywordObject = “Text”)
public static boolean verifyElementText(ResponseObject response, String locator, String text) {
response.responseText = (response.responseText =~ ‘<soap:Envelope.*</soap:Envelope>’)[0]
return WSBuiltInKeywords.verifyElementText(response, locator, text)
}

@CompileStatic
@Keyword(keywordObject = “Text”)
public static boolean verifyElementText(ResponseObject response, String locator, String text, FailureHandling flowControl) {
response.responseText = (response.responseText =~ ‘<soap:Envelope.*</soap:Envelope>’)[0]
return WSBuiltInKeywords.verifyElementText(response, locator, text, flowControl)
}
}`

Hi,

I tried it already. It didn’t work. As you can see in my original post, the path is: ns2:getProductResponse.Product.Reference

Regards

PS: Can you please update your answer to change the reference to “MyReference”?

Hello Vinh,

No, it is accessible within the VPN.

Regards

Hi there,

Please ignore my previous comment. I’ve found out a solution for you:

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

def response = WS.sendRequest(findTestObject('ProductById'))

response.responseText = (response.responseText =~ '<soap:Envelope.*</soap:Envelope>')[0]
WS._verifyElementText_(response, "getProductResponse.Product.Reference", "MyPreference")

http://prntscr.com/g3b97a
So the solution is to split valid soap response:response.responseText = (response.responseText =~ ‘<soap:Envelope.*</soap:Envelope>’)[0] and use it for verification in next verification steps.

I also adjust verifyElementText to select correct locator as well.

Hi there,

I’ve found the following topic regard to configurations of your web service, can you take a look at one of them:

I think uuid is the main reason here which throwing error for XML parsing

Hi there, can you adjust your ‘verifyElementText’ like this:

WS.verifyElementText(response, "getProductResponse.Product.Reference", "MyReference")

Your starting locator begins from its body

Is your web service accessible from outside?