2016-11-29 32 views
1

我正在學習groovy語言並使用SOAP進行測試,同時我也是語言的新手。我只是運行我的加載腳本,但我想通過另一個文件名打印出我的請求和響應。我可以打印請求/響應,但可以寫入同一個文件。Groovy:使用不同文件名打印

這裏是我的路徑:

def outputPath = "C:/FileName/" 

outputPath = outputPath 

def folder = new File(outputPath) 

if(!folder.exists()) { 
    folder.mkdirs() 
} 

return outputPath 

,這裏是我的打印輸出:

def request = context.expand('${Script1#Request}') 
def response = context.expand('${Script1#Response}') 
def outputPath = context.expand('${init#result}') 

def requestPath = outputPath + "/Script1_req.xml" 
def responsePath = outputPath + "/Script1_res.xml" 

def f = new File(requestPath) 
f.write(request, "UTF-8") 

def f2= new File(responsePath) 
f2.write(response, "UTF-8") 

我如何印出我everyscript與像例如script1_req(1-XXXX)的.xml另一個文件名?

謝謝你的回答。

+0

你的意思是,「請求和響應被覆蓋在測試運行了多次」。那麼,你想保存在一個獨特的文件? – Rao

+0

是的,你是對的。我嘗試寫長文件名到文件名,但我失敗了。 –

+0

謝謝您的確認,請嘗試提供的答案。 – Rao

回答

0

您只需要爲文件名添加獨特的值。

昌下面兩個語句

def requestPath = outputPath + "/Script1_req.xml" 
def responsePath = outputPath + "/Script1_res.xml" 

要:

//Get the date in the given format 
​def date = new Date().format('yyyyMMddHHmmss') 
def requestPath = "${outputPath}/Script1_req_${date}.xml" as String 
def responsePath = "${outputPath}/Script1_res_${date}.xml" as String