Tha*_*ven 5 groovy soap soapui
我在SoapUI中创建了一些测试.我要测试的SOAP请求有附件.当我正在设置它时,一切都很好:

但就我而言,我需要动态设置附件.我试图通过属性来保存文件路径,并使用groovy脚本来设置附件.但它根本不起作用:
// 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())
}
Run Code Online (Sandbox Code Playgroud)
运行此脚本后,请求如下所示:

SoapUI的文档根本没用.所以,我的问题是:我做错了什么?
我找到了答案:
def holder2 = groovyUtils.getXmlHolder( "UploadRoutingCodes#Request" ) // Get Request body
def startDate2 = holder2.setNodeValue( "//blac:FileByteStream","cid:"+list.last()); //Set "link" to attachment in request body
holder2.updateProperty() //and update
attachment.setPart(list.last()); //set attachment
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8512 次 |
| 最近记录: |