title: Attaching file in SoapUI with groovy
body: <p>I'm creating some tests in SoapUI. SOAP request, that i want to test has attachment. When I'm setting it manualy, everything is ok:
  <img src="https://i.stack.imgur.com/oaaUn.png" alt="Designer view">
  <img src="https://i.stack.imgur.com/ddRYH.png" alt="part of raw request"></p>
  
  <p>But in my case, i need to set attachment dynamically. I'm trying to made it by properties to hold file path, and groovy script to set attachment. but it's not work at all:</p>
  
  <pre><code>// get request
  def request = testRunner.testCase.getTestStepByName( "UploadRoutingCodes" ).testRequest
  
  // clear existing attachments
  for( a in request.attachments ) {
     request.removeAttachment( a )
  }
  
  // get file to attach
  //def fileName = context.expand( '${Source of data#PathToXRC File data name }' )
  def fileName = context.expand( '${#TestCase#XRC_file_name}' )
  def filePath = context.expand( '${#Project#XRC_files_path}' )
  
  log.info "file: " + filePath + fileName
  def file = new File(filePath + fileName  )
  if ( file == null) {
     log.error "bad filename"
  }
  else 
  {
     // attach and set properties
     def attachment = request.attachFile( file, true )
     attachment.contentType = "application/octet-stream"
     def list = fileName.tokenize("\\");
     attachment.setPart(list.last())
  }
  </code></pre>
  
  <p>After run this script, request look like this:
  <img src="https://i.stack.imgur.com/65YX2.png" alt="Designer view">
  <img src="https://i.stack.imgur.com/mpNKU.png" alt="part of raw request"></p>
  
  <p>Documentation to SoapUI is not helpful at all.
  So, my question is: what i'm doing wrong?</p>