需求: 从文件夹中读取xml文件,并将文件内容传递给Soap请求。
问题: 我正在尝试使用Groovy脚本读取保存在文件夹中的文件,但无法读取文件的内容。在尝试打印xml文件的内容时,我遇到了空指针异常。
def fileList = []
new File("C:\\Users\\Documents\\Groovy Scripts\\requests").eachFile
{ f ->
if (f.isFile()&& f.name.endsWith('.xml'))
{
def filename = f.name[0..-5]
fileList.add(filename)
log.info filename
}
}
if (fileList.size() <1)
{
testRunner.fail("No request files found")
}
context.put('fileList', fileList)
def f = new File("C:\\Users\\Documents\\Groovy Scripts\\requests\\${context.fileList}.last().text")
log.info f
根据评论更新,补充问题。
我的测试用例包含3个步骤。步骤1:从文件夹中读取XML文件。步骤2:使用XML文件内容作为SOAP请求输入。步骤3:将步骤2的响应保存在输出文件夹中作为XML。