使用Groovy在SoapUI中自动保存附件 [英] Save attachments automatically in SoapUI with Groovy

查看:165
本文介绍了使用Groovy在SoapUI中自动保存附件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试保存SOAP响应中的所有附件.我使用以下Groovy脚本.

I try to save all the attachments from a SOAP response. I use following Groovy script.

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

我收到以下错误消息:

没有此类属性:类的responseAttachments

No such property : responseAttachments for class

推荐答案

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

Use following script in assertion (Script assertion) in 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()

这篇关于使用Groovy在SoapUI中自动保存附件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆