2016-09-21 86 views
-2

雖然肥皂(免費版)有一個選項來導出生成的文件作爲迴應。有沒有任何groovy函數來提取應用程序/ pdf文件並存儲在我的本地文件夾?如何使用groovy從肥皂響應中導出pdf附件?

enter image description here

+0

採取你tryed任何解決方案? – adalPaRi

+0

@adalPaRi - 我是groovy的新手,但是知道VB腳本。我無法找到將提取PDF文件,與肥皂響應一起出現的函數。但是,我可以使用groovy在文本文件中保存響應。 – Rish

回答

0

下面的腳本應該能夠附件保存到文件中。

將以下腳本作爲Script Assertion添加到當前請求步驟。內嵌找到適當的評論。爲腳本

來源是here

/** 
* Below script assertion will check 
* if the response is not null 
* there is an attachment 
* and saves file to the specified location, by default saves into system temp 
* directory 
**/ 
//change file name as needed 
def fileName = System.getProperty('java.io.tmpdir')+'/test.pdf' 

//Get the response and check if the response is not null 
def response = messageExchange.response 
assert null != response, "response is null" 

//Create output stream 
def outFile = new FileOutputStream(new File(fileName)) 

//Check if there is one attachment in the response 
assert 1 == messageExchange.responseAttachments.length, "Response attachments count not matching" 
def ins = messageExchange.responseAttachments[0]?.inputStream 
if (ins) { 
    //Save to file 
    com.eviware.soapui.support.Tools.writeAll(outFile, ins) 
} 
ins.close() 
outFile.close() 
+0

感謝分享腳本!我得到錯誤爲「沒有這樣的屬性:responseAttachment的類:..」 – Rish

+0

Stacktrace請嗎?提供給您的腳本具有'messageExchange.responseAttachments',而不是'responseAttachment'。它是附件列表,所以's',但你指的是單一的。你用過嗎?或修改?提供的答案是其他類型文件的測試樣本,所以在這種情況下不應該有任何問題。 – Rao

+0

其工作正常。 – Rish