2016-08-19 51 views
-2

我使用SOAPUI發送請求,並且需要在文本/ XML消息的末尾添加一個製表符/空格,以便服務器和我接受得到適當的迴應。我需要一個Groovy腳本,它將簡單地將一個選項卡添加到文本/ XML請求的末尾。謝謝Groovy腳本在文本/ XML請求結尾處添加一個選項卡SOAPUI

+0

「我需要一個Groovy腳本,將只需要添加一個標籤到文本/ XML請求結束「。好。那麼爲什麼不寫一個呢? – rmlan

+3

爲什麼您首先需要額外的選項卡/空間才能被服務器接受?相反,修復。 –

回答

0

在評論中提到的方法是修復您的WS在請求結束時無需額外的選項卡/空間即可正常工作。

另一個簡單的選項,如果您不能修復de WS因爲它是第三方服務,那麼只需在testStep中手動添加一個選項卡作爲請求的一部分。因爲有些時候

Anywise是必要的或util的修改某些其他原因,我會告訴你如何得到SOAP請求的Groovy腳本來操縱它的一個示例的請求。你可以這樣做增加了Groovy的一步步測試用下面的代碼:

// 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) 

希望它能幫助,

+0

非常感謝你!這是一個第三方服務,所以,可惜我無法修復實際的服務。 –

相關問題