Forum Discussion

jserafin's avatar
13 years ago

Attaching file in SoapUI with groovy

hi there!

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:




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 and it's not work at all:
// 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())
}


After run this script, request look like this:



Documentation to SoapUI is not helpful at all. So, my question is: what i'm doing wrong? How I can set FileByteStream field of request to set attachment?

Regards
J. Serafin