使用groovy在SoapUI中附加文件
发布时间:2020-12-14 16:25:05 所属栏目:大数据 来源:网络整理
导读:我在SoapUI中创建了一些测试.我要测试的SOAP请求有附件.当我正在设置它时,一切都很好: 但就我而言,我需要动态设置附件.我试图通过属性来保存文件路径,并使用groovy脚本来设置附件.但它根本不起作用: // get requestdef request = testRunner.testCase.getT
我在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()) } 运行此脚本后,请求如下所示: 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 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |