plaidshirt
2 years agoContributor
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 com.eviware.soapui.support.GroovyUtils(context) 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 { it.name() == 'name' }.toString(); out_filename = out_filename.substring(1, out_filename.length() - 1); props.setPropertyValue("out_filename",out_filename); 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) { com.eviware.soapui.support.Tools.writeAll(outFile, ins) } ins.close() outFile.close()
It is successfully saved, when I execute it manually, but it fails when SOAP request is executed. Error: out_filename is null.