Need help with groovy script command to archive xml file after processing
I am new to SoapUI and Groovy but after a lot of research I was able to build a simple TestCase with 3 steps that loops through all *.xml files in a folder, submits them one at a time automatically, and captures the responses in a separate folder. It works great except it leaves the original XML message in the Requests folder and I'd like to move the file, after the Response file is created successfully, and rename it with ".xml.processed". The archive folder path would be C:\XML_SUBMISSION\XML_Requests\archive\.
I've spent hours researching "archiving" or "moving" xml requests after submission and have tried numerous renaming samples but nothing seems to work. I would think this would be a somewhat common practice when testing multiple submissions.
Here is the code:
Step 1 to get the file name:
def fileList = [] new File("C:\\XML_SUBMISSION\\XML_Requests").eachFile { f -> if (f.isFile()&& f.name.endsWith('.xml')) { def filename = f.name[0..-1] fileList.add(filename) //log.info filename } } if (fileList.size() <1) { testRunner.fail("No request files found") } context.put('fileList',fileList)
Step 2 is the SoapUI Submission:
${=new File("C:\\XML_SUBMISSION\\XML_Requests\\" + (context.get('fileList')).last()).text}
Step 3 to capture the Response and loop back to Step 2:
def fileList = context.get('fileList') def fileName = fileList.pop() def newname = fileName[0..-5] def response = context.expand( '${Step2#Response}' ) def f = new File("C:\\XML_SUBMISSION\\XML_Responses\\${fileName}_Response.xml") f.write(response, "UTF-8") //I thought the archiving command would go here but maybe at Step 3 I no longer have the original file context? if(fileList.size() >0) { testRunner.gotoStepByName("Step2") }
It seems like this is simple and I'm just missing something. Any help you're able to provide would be appreciated.
Thank you.