Search code examples
groovysoapuibytearrayinputstream

SoapUI to get attachment from response in Groovy


I tried to use following code to get attachment from reponse as text in Groovy.

def testStep = testRunner.testCase.getTestStepByName("getData")
def response = testStep.testRequest.response
def ins =  response.attachments[0].inputStream
log.info(ins);

It contains some binary information too, so it is not fully human readable, but got following in output:

java.io.ByteArrayInputStream@5eca74


Solution

  • It is easy to simply encode it to base64 and store it as a property value.

    def ins =  response.attachments[0].inputStream
    String encoded = ins.bytes.encodeBase64().toString()