Forum Discussion

plaidshirt's avatar
2 years ago

get value from SOAP response in Script Assertion

I try to save attachment from SOAP response using following Groovy script as Script Assertion in SoapUI.

def groovyUtils = new
def props = messageExchange.modelItem.testStep.testCase.getTestStepByName("Properties")
def outputDir = new File(context.expand('${Properties#outputFolder}'))

responseContent = context.response
def parsedXML = new XmlSlurper().parseText(responseContent)
def out_filename = parsedXML.'**'.findAll { == 'name' }.toString();
out_filename = out_filename.substring(1, out_filename.length() - 1);

def fileName = outputDir.toString() +  '\\' + out_filename
def response = messageExchange.response
assert null != response, "response is null"
def outFile = new FileOutputStream(new File(fileName))
def ins = messageExchange.responseAttachments[0]?.inputStream

if (ins) {, ins)

It is successfully saved, when I execute it manually, but it fails when SOAP request is executed. Error: out_filename is null.

No RepliesBe the first to reply