Mahmut Develioğlu Mahmut Develioğlu - 1 year ago 177
Groovy Question

Groovy: Print with different file names

I'm learning groovy language and use SOAP for my tests, also I'm newbie for languages. I just run my load script but I want printout my request and responses via another filename. I can print requests/responses but writes on same file.

Here is my path:

def outputPath = "C:/FileName/"

outputPath = outputPath

def folder = new File( outputPath )

if( !folder.exists() ) {

return outputPath

And here is my printout:

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")

How can I printout my everyscript with another file name like example script1_req(1-XXXX).xml ?

Thank you for your answers.

Rao Rao
Answer Source

All you need to is to have unique value to be appended for the file name.

Chang below two statements

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
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download