2016-09-21 85 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