Tori Swartz Tori Swartz -4 years ago 226
Groovy Question

Groovy Script to add a tab at end of text/XML Request SOAPUI

I am sending a request using SOAPUI and need to add a tab/space at the end of the text/XML message so it is accepted by the server and I get the proper response. I need a Groovy script that will simply add a tab to the end of the text/XML request. Thanks

Answer Source

The way to go as it's said in the comments is to fix your WS to work correctly without the extra tab/space at the end of your request.

Another simple option if you can't fix de WS because it's a third party service, it's simply to add manually a tab in the testStep as part of your request.

Anywise since some times is necessary or util to modify the request for some other reason I will show you an example of how to get the SOAP Request with a Groovy script to manipulate it. You can do it adding a Groovy testStep with the following code:

// get the testStep by name
def testStep = testRunner.testCase.getTestStepByName('Your request name')
// get request content
def originalRequestContent = testStep.getPropertyValue('request')

// perform your modifications...
// in your case simply add a new tab
def newRequestContent = "${originalRequestContent}\t"
// as tab is not showed in the Raw tab of your testStep, 
// to show that this code work as expected I add 
// and unnecessary extra text
newRequestContent += 'it works'

// set the new modified request
// and finally you can send the request,context)
// if you want to keep the step as orignal uncomment
// the follow line
// testStep.setPropertyValue('request',originalRequestContent)

Hope it helps,

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download