Forum Discussion

Rene_Single's avatar
Rene_Single
Occasional Contributor
16 years ago

Modifying Request Attachment through Groovy

Hi everybody,

I'm looking for a way to modify an attachment of a request through a groovy script. I need to add some data to the attachment obtained from a prior test Step.

I could probably modify the file representing the attachment in the filesystem and not cache it in the request, but I'm having a hard time figuring out how to do that.

Has anybody already done something like this and can shed some light (share some code  ) on this ?


René
  • SmartBear_Suppo's avatar
    SmartBear_Suppo
    SmartBear Alumni (Retired)
    Hello,

    In the upcoming nightly build of soapUI there are some new methods defined for the Attachment object. These are getData and setData which return and take a byte[]. This allows you to modify the attachment data in memory (without changing the file in the filesystem). In groovy you could access this using:


    testRunner.testCase.testSteps['Your Request Name'].httpRequest.getAttachmentAt(0).data


    which is both readable and writable. Good luck!

    Regards,
    Dain
    eviware support
    • bkbn16's avatar
      bkbn16
      Contributor

      I tried this "

      testRunner.testCase.testSteps['Your Request Name'].httpRequest.getAttachmentAt(0).data

      "

       

      But I am getting error...

       

      java.lang.NullPointerException: Cannot get Property 'httpRequest' on null object. Please help