2016-11-29 79 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