Replace SOAP Test Object Body XML

I am attempting to use the contents of a variable to replace the body of a SOAP request in the Object Repository as in:

import com.kms.katalon.core.testobject.RequestObject as RequestObject

RequestObject request = findTestObject(‘New SOAP Request’)

strSOAPBody = ‘’’<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi=“” xmlns:xsd=“XML Schema” xmlns:soap12=“”>


‘Change SOAP Body’

The problem is that the SOAP Request Object in the repository requires body text to be present (either ‘hard coded’ or from a file) in order to work. That text is always used instead of what is defined in the variable and ‘set’ via .setSoapBody(strSOAPBody). How can I replace that text with what is in the variable?


I have tried the setSoapBody() function and saw that the Body could be set to new value.

RequestObject request = findTestObject(‘SOAP_ConvertWeight’);

request.setSoapBody(“should be fail”);

Does it only happen with variable or could you replace the variable with a new soapbody?

It fails using text directly too as in

request.setHttpBody("""<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi=“” xmlns:xsd=“” xmlns:soap12=“”>


I think the multi-lined XML with embedded quotes just isn’t handled well by the repository object. This is a shame, because tools like Jmeter allow you to substitute freely as in ${strIPAddress}. Groovy supports this too. Reading in from a file works, but I can’t substitute anything. I am trying to do data driven API testing (like I can with Jmeter).


I have following script working. Could you have a look on it and adjust with your case? In the example, I replace the variable “weight” in the script mode, print the body out for verification before submit the result.

‘Send a SOAP request and returns its response’

RequestObject request = findTestObject(‘SOAP_convertWeight’)

String body = “”"<?xml version="1.0" encoding="utf-8"?>

<soap:Envelope xmlns:xsi=“” xmlns:xsd=“” xmlns:soap=“”>


<ConvertWeight xmlns="http://www.webserviceX.NET/">








request.setSoapBody(String.format(body, weight))


//def response = WS.sendRequest(findTestObject(‘SOAP_ConvertWeight’))

def response = WS.sendRequest(request)


‘Verify converted weight after sending request is correct or not’

WS.verifyElementText(response, ‘ConvertWeightResult’, ‘3000’)

request.setSoapBody(String.format(strSOAPBody)) worked.
response = WS.sendRequest(request) worked.
WS.verifyElementText(response, ‘GetGeoIPResponse.GetGeoIPResult.IP’, ‘’). worked.

I can substitute parameters by playing with the XML string.

OK, thanks for this.

BTW … request.setSoapBody(strSOAPBody) worked too … String.format was not required.

I consider this solved.

Final script that works (variables BOLD)! :slight_smile:

RequestObject request = findTestObject(‘New SOAP Request - Copy’)

// read Object Repository (request), substitute, and send local object (request) not repository object
// then compare against response and not repository object
// use repository object as a template or abstract class (create new based on it)

def strSOAPBody = “”"<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi=“” xmlns:xsd=“” xmlns:soap12=“”>



‘Set Soap Body equal to XML string’


‘Send IP address and get response.’
response = WS.sendRequest(request)

‘Expect 200 HTTP response (found).’
WS.verifyResponseStatusCode(response, 200)

‘Verify return IP address sent.’
WS.verifyElementText(response, ‘GetGeoIPResponse.GetGeoIPResult.IP’, strIPAddress)

‘Verify location country of IP address returned.’
WS.verifyElementText(response, ‘GetGeoIPResponse.GetGeoIPResult.CountryName’, strLocation)