我尝试保存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()
我收到以下错误消息:
没有此类属性:类的responseAttachments
答案 0 :(得分:1)
responseAttachments
是MessageExchange
上的一个属性。您使用的是Response
,因此您需要使用attachments
。有关更多详细信息,请参见API docs。
答案 1 :(得分:1)
在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()
答案 2 :(得分:1)
def testCaseName = 'Messages-IP-Mail'
def testStepName = '001_1ConventMailToPDF'
//context.testCase.testSuite.testCases[testCaseName].testSteps[testStepName].testRequest.responseContent
def projectDir = context.expand('${projectDir}');
log.info "Current dir:" + projectDir
def response = context.testCase.testSuite.testCases[testCaseName].testSteps[testStepName].testRequest.response.getAttachments()
def fileName = projectDir + '/pdf.pdf'
def outFile = new FileOutputStream(new File(fileName))
testRunner.testCase.testSteps["fileName"].setPropertyValue("fileName", fileName)
def ins = response[0].inputStream
if (ins) {
com.eviware.soapui.support.Tools.writeAll(outFile, ins)
}
ins.close()
outFile.close()