我正在学习groovy语言并使用SOAP进行测试,我也是语言的新手。我只是运行我的加载脚本,但我想通过另一个文件名打印我的请求和响应。我可以打印请求/响应,但写在同一个文件上。
这是我的路径:
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 :(得分: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