使用Groovy在SoapUI中自动保存附件

使用Groovy在SoapUI中自动保存附件,groovy,soapui,Groovy,Soapui,我试图保存SOAP响应中的所有附件。我使用下面的Groovy脚本 def testStep = testRunner.testCase.getTestStepByName("SubmitFile") def response = testStep.testRequest.response assert null != response, "response is null" def outFile = new FileOutputStream(new File(System.getPropert

我试图保存
SOAP
响应中的所有附件。我使用下面的
Groovy
脚本

def testStep = testRunner.testCase.getTestStepByName("SubmitFile")
def response = testStep.testRequest.response
assert null != response, "response is null"
def outFile = new FileOutputStream(new File(System.getProperty('java.io.tmpdir')+'/test.zip'))
for(i=0; i<3; i++){
    def ins =  response.responseAttachments[0].inputStream
    if (ins) {
       com.eviware.soapui.support.Tools.writeAll(outFile, ins)
    }
}
ins.close()
outFile.close()
def testStep=testRunner.testCase.getTestStepByName(“SubmitFile”)
def response=testStep.testRequest.response
断言为空!=响应,“响应为空”
def outFile=new FileOutputStream(新文件(System.getProperty('java.io.tmpdir')+'/test.zip'))

对于(i=0;i
responseAttachments
MessageExchange
上的一个属性。您使用的是
Response
,因此需要
attachments
。有关详细信息,请参阅。

responseAttachments
MessageExchange
上的一个属性。您使用的是
Response
,因此需要
attachment改为使用脚本
。有关更多详细信息,请参阅。

在Soap UI中的断言(脚本断言)中使用以下脚本

def response = messageExchange.response
assert null != response, "response is empty"

def outFile
def inputStream
    if(messageExchange.responseAttachments.size() >0){
            inputStream =  messageExchange.responseAttachments[0].inputStream
        if (inputStream) {
              outFile = new FileOutputStream(new File('/Users/sys/Documents/test/bank_response.txt'))
           com.eviware.soapui.support.Tools.writeAll(outFile, inputStream)

        }
    }else{
        log.error 'No attachments found!!!'
    }

if(inputStream) inputStream.close()
if(outFile) outFile.close()

在SOAPUI的断言(脚本断言)中使用以下脚本

def response = messageExchange.response
assert null != response, "response is empty"

def outFile
def inputStream
    if(messageExchange.responseAttachments.size() >0){
            inputStream =  messageExchange.responseAttachments[0].inputStream
        if (inputStream) {
              outFile = new FileOutputStream(new File('/Users/sys/Documents/test/bank_response.txt'))
           com.eviware.soapui.support.Tools.writeAll(outFile, inputStream)

        }
    }else{
        log.error 'No attachments found!!!'
    }

if(inputStream) inputStream.close()
if(outFile) outFile.close()