用Groovy在SoapUI中附加文件 [英] Attaching file in SoapUI with groovy
本文介绍了用Groovy在SoapUI中附加文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在SoapUI中创建了一些测试。 SOAP请求,我想测试的附件。当我将它设置为manualy时,一切正常:
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:
但在我的情况下,我需要动态设置附件。我试图通过属性来保存文件路径,并使用groovy脚本来设置附件。但它根本不起作用:
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. but 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:
SoapUI的文档根本没有任何帮助。
所以,我的问题是:我做错了什么?
Documentation to SoapUI is not helpful at all. So, my question is: what i'm doing wrong?
推荐答案
我找到了答案:
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
这篇关于用Groovy在SoapUI中附加文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文