使用 groovy 在 SoapUI 中附加文件
我正在 SoapUI 中创建一些测试。我想测试的 SOAP 请求有附件。当我手动设置时,一切正常:
但就我而言,我需要动态设置附件。我试图通过属性来保存文件路径,并通过常规脚本来设置附件。但它根本不起作用:
// 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 的文档根本没有帮助。 所以,我的问题是:我做错了什么?
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. 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:
Documentation to SoapUI is not helpful at all.
So, my question is: what i'm doing wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我找到了答案:
I found the answer:
塞文,谢谢你的回答。这有帮助。我将附上我完整的绝妙脚本,因为我花了一些时间来完全组装你的部件,但无论如何,所有的敬意都归于你。
请注意:
是测试用例内定义的测试步骤属性。 文件名:my_sample_filename.xml 和文件名路径:C:\samples\my_sample_filename.xml 相应。
这是我的肥皂要求:
Thaven, thank you for your answer. It helped. I will attach my full groovy script as I spent some time to fully assembled your parts, but anyhow all tributes goes to you.
Please note that:
are the test step properties defined inside the test case. Filename: my_sample_filename.xml and FileNamePath: C:\samples\my_sample_filename.xml accordingly.
And here is my soap request: