如何使用groovy从soap回复中导出pdf附件?

问题描述 投票:0回答:2

虽然soap(免费版本)有一个选项可以导出响应中生成的文档。是否有任何常规功能可以提取应用程序/pdf 文件并存储在我的本地文件夹中?

enter image description here

groovy soapui
2个回答
2
投票

以下脚本应该能够将附件保存到文件中。

将以下脚本作为

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
投票

我必须对代码进行一些调整,但 Rao 提供的解决方案对我有用。 如果您在请求后使用脚本作为测试步骤,要使用 messageExchange,我必须通过以下方式访问它:

testStep.testRequest.messageExchange

除此之外,这是一个有效的解决方案。干杯。

© www.soinside.com 2019 - 2024. All rights reserved.