我在SoapUI中創建了一些測試。 SOAP請求,我想測試的附件。當我manualy設置它,一切都很好: 使用groovy在SoapUI中附加文件
但於我而言,我需要動態設置附件。我試圖通過屬性來保存文件路徑,並使用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是沒有幫助的。 所以,我的問題是:我做錯了什麼?