Groovy 在 text/XML 请求 SOAPUI 末尾添加选项卡的脚本

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

我正在使用 SOAPUI 发送请求,需要在 text/XML 消息的末尾添加一个 tab/space 以便它被服务器接受并且我得到正确的响应。我需要一个 Groovy 脚本,它只会在 text/XML 请求的末尾添加一个选项卡。谢谢

评论中所说的方法是修复您的 WS 以使其正常工作,而无需在请求末尾添加额外的 tab/space。

另一个简单的选项,如果您无法修复 de WS,因为它是第三方服务,只需在 testStep 中手动添加一个选项卡作为您请求的一部分。

无论如何,由于某些时候是必要的或出于某些其他原因修改请求,我将向您展示一个示例,说明如何使用 [=19= 获取 SOAP 请求 ]Groovy 脚本来操作它。您可以使用以下代码添加 Groovy testStep

// 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
testStep.setPropertyValue('request',newRequestContent)
// and finally you can send the request
testStep.run(testRunner,context)
// if you want to keep the step as orignal uncomment
// the follow line
// testStep.setPropertyValue('request',originalRequestContent)

希望对您有所帮助,