Forum Discussion

bkbn16's avatar
bkbn16
Contributor
8 years ago

Unable to fetch response JPEG attachments

For the past few days, I have been trying to create a POST response with a image attached (JPEG). I need to get the output as response attachment in JPEG format. How can I do this ? Please see the attachments that I have posted on the procedure that I have followed to do this ...

3 Replies

  • nmrao's avatar
    nmrao
    Champion Level 3
    You need to create a test suite -> test case and add the test step and then try attaching it. You can't use the attachment from the rest method definition which you doing it currently.
    • bkbn16's avatar
      bkbn16
      Contributor

      Hi,

       

      I followed your instructions, created a REST project and under that Test Suite > Test Case > Test Script. Then I created a httprequest. I uploaded a image jpeg file. Along with the httprequest, I am writing a Groovy script to fetch the same uploaded image file as response. I have been followng the thread "https://community.smartbear.com/t5/SoapUI-Open-Source/Saving-attachments-automatically/m-p/122169#M21030" to do the same.

       

      My script is like this:

       

      import java.lang.*
      import java.util.*
      import java.io.*
      import java.net.*
      import groovy.lang.*
      import groovy.util.*
      import java.math.BigInteger
      import java.math.BigDecimal
      import javax.servlet.http.*
      def groovyUtils=new com.eviware.soapui.support.GroovyUtils(context)
      import com.eviware.soapui.model.iface.*

      def ImageReq = testRunner.testCase.testSteps['LeeChin'].httpRequest.getAttachmentAt(0)
      log.info(ImageReq) /* This points to the Request Attachment properly */

      def ImageResponse = testRunner.testCase.testSteps['LeeChin'].httpRequest.response
      //assert null != response, "response is null"
      def outFile = new FileOutputStream(new File(System.getProperty('java.io.tmpdir')+'/test.zip'))
      def ins = ImageResponse.getAttachmentAt[0].inputStream /* error */
      if (ins) {
      com.eviware.soapui.support.Tools.writeAll( outFile, ins )
      }
      ins.close()
      outFile.close()

       

      When I run the script; I get an error No such property "getAttachmentAt"; then I changed it to "responseAttachments"

       I again get the same error; what am I doing wrong ?

      • nmrao's avatar
        nmrao
        Champion Level 3
        Please show the screen shot of your request?