Ask a Question

Attaching file in SoapUI with groovy

Not applicable

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}' ) "file: " + filePath + fileName
def file = new File(filePath + fileName )
if ( file == null) {
log.error "bad filename"
// attach and set properties
def attachment = request.attachFile( file, true )
attachment.contentType = "application/octet-stream"
def list = fileName.tokenize("\\");

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?

J. Serafin
New Contributor

Re: Attaching file in SoapUI with groovy

Showing results for 
Search instead for 
Did you mean: