0

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

plaidshirt
  • 5,189
  • 19
  • 91
  • 181
  • 1
    You need to convert to string first. Here's an SO link on [Converting Contents Of A ByteArrayInputStream To String](https://stackoverflow.com/questions/24059266/convert-contents-of-a-bytearrayinputstream-to-string) – Chris Adams Feb 06 '19 at 11:21

1 Answers1

0

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()
plaidshirt
  • 5,189
  • 19
  • 91
  • 181