Twain, thanks for your reply. That helped. I will attach my full groovy script, as I have spent some time completely assembling your parts, but somehow the tribute goes to you.
Note:
//FileNamePath def fileNamePath = testCase.getTestStepAt(testRunner.testCase.getTestStepIndexByName("FileNameProperties")).getProperty("FileNamePath") //FileName def fileName = testCase.getTestStepAt(testRunner.testCase.getTestStepIndexByName("FileNameProperties")).getProperty("FileName")
- These are the properties of the test step defined within the test case. File name: my_sample_filename.xml and FileNamePath: C: \ samples \ my_sample_filename.xml, respectively.
import groovy.xml.MarkupBuilder import org.custommonkey.xmlunit.* import java.util.Random import java.security.MessageDigest import java.nio.file.* def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context) def projectPath = groovyUtils.projectPath log.info projectPath def project = testRunner.testCase.testSuite.project log.info "Project: " + project.name def myTestSuite = testRunner.testCase.testSuite; log.info "TestSuite: " + myTestSuite.name def testCase = testRunner.testCase log.info "TestCase: " + testCase.name def testStepUploadDataAfterCheck = testCase.getTestStepByName("UploadDataAfterCheck") def request= testStepUploadDataAfterCheck.testRequest log.info "TestStep: " + testStepUploadDataAfterCheck.name // clear existing attachments for( a in request.attachments ) { request.removeAttachment( a ) } //FileNamePath def fileNamePath = testCase.getTestStepAt(testRunner.testCase.getTestStepIndexByName("FileNameProperties")).getProperty("FileNamePath") //FileName def fileName = testCase.getTestStepAt(testRunner.testCase.getTestStepIndexByName("FileNameProperties")).getProperty("FileName") // get file to attach log.info "file to attach: " + fileNamePath.getValue() def file = new File(fileNamePath.getValue() ) if ( file == null) { log.error "bad filename" } else { // attach and set properties def attachment = request.attachFile( file, true ) attachment.contentType = "application/octet-stream" attachment.setPart(fileName.getValue()) def holder2 = groovyUtils.getXmlHolder( "UploadDataAfterCheck#Request" ) // Get Request body holder2.setNodeValue( "//upl:UploadDataAfterCheckRequest/uploadedData","cid:"+fileName.getValue()); //Set "link" to attachment in request body holder2.updateProperty() //and update log.info "file attached succesfully" }
And here is my request for soap:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:upl="http://www.acer.europa.eu/aris/upload"> <soapenv:Header/> <soapenv:Body> <upl:UploadDataAfterCheckRequest> <uploadedData>cid:my_sample_filename.xml</uploadedData> </upl:UploadDataAfterCheckRequest> </soapenv:Body> </soapenv:Envelope>
source share