【发布时间】:2014-06-12 12:13:55
【问题描述】:
我正在使用 SoapUI Pro 为一家邮政公司测试一组 Web 服务。
作为测试用例的一部分,我生成 pdf 格式的标签和清单文档。我将这些 pdf 文件存储在一个文件夹中,该文件夹由测试用例开始时的 groovy 脚本创建。有时,当我运行测试时,不会生成标签或 pdf,因为我正在测试错误代码,即使用不会创建发货的测试输入,因此不会生成标签。
我在测试用例末尾有一个脚本,如果我创建的文件夹为空,它将删除它。如果它不为空,即其中有标签 pdf,我想修改它以压缩整个文件夹。但不确定如何执行此操作。
以下是我删除空文件夹的脚本。抱歉,我没有尝试任何代码来进行压缩。
import groovy.xml.NamespaceBuilder
import org.apache.tools.antBuilder.*
//This script deletes the pdf sub folder created by 'CreateFolderForPDFs' if no pdfs are generated as part of test
// i.e test does not produce valid shipments.
def pdfSubFolderPath = context.expand( '${#TestCase#pdfSubFolderPath}' )
def pdfSubFolderSize = new File(pdfSubFolderPath).directorySize()
if( pdfSubFolderSize == 0){
new File(pdfSubFolderPath).deleteDir()
log.info "Deleted the pdf sub folder " +pdfSubFolderPath +"because contains no pdfs"
}
else
{
//zip folder and contents
}
【问题讨论】: