要求:從該文件夾讀取xml文件並將該文件的內容傳遞給Soap請求。Groovy腳本讀取一個xml文件並更新文件內容的下一步請求
問題我正在嘗試使用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文件內容作爲肥皂請求輸入。步驟3:將輸出文件夾中步驟2的響應保存爲xml。
你在做數據驅動的測試嗎?你能展示你的測試用例的結構嗎? – Rao
的可能的複製[如何閱讀在Groovy文件轉換成字符串?](http://stackoverflow.com/questions/7729302/how-to-read-a-file-in-groovy-into-a-string) – Rao
我的測試用例包含3個步驟。第1步:從文件夾中讀取xml文件。第2步:使用XML文件內容作爲肥皂請求輸入。步驟3:將輸出文件夾中步驟2的響應保存爲xml。 – user3212324