hellrid1
14 years agoOccasional Contributor
get filename from XML request file in directory datasource
I have a DataSource that reads XML files from a directory using a DataSource loop
for SoapUI Pro Version 4.0.
I also have a Groovy script that writes the XML response to a file in another directory.
Currently, it uses a time/date stamp to name each XML Response file.
I would like to get the filename for each file that is read from the datasource, and use
the input filename to rename the output response XML files, so that I can tell which
response file corresponds to which input request file.
Also, I want to do this using a Groovy script.
Here is a copy of my current Groovy script that uses a time/date stamp to name the files:
date = new Date();
dateFormat = new java.text.SimpleDateFormat('MM-dd-yyyy');
dateStamp = dateFormat.format(date);
createFolder = new File("c:/Output/Responses " + dateStamp);
createFolder.mkdir();
time = new Date();
timeFormat = new java.text.SimpleDateFormat("HH.mm.ss.SS");
timeStamp = timeFormat.format(time);
def FileName = new PrintWriter( new FileWriter( "c:/Output/Responses " + dateStamp + "/" + dateStamp + " " + timeStamp + " response.xml.txt" ));
def ResponseMessage = testRunner.testCase.testSteps["Test Request"].testRequest.response.contentAsString;
def request = testRunner.testCase.getTestStepByName( "Test Request" );
def req = request.getProperty( "Request" );
def resp = request.getProperty( "Response" );
FileName.print( resp.value );
FileName.flush();
FileName.close();
log.info( resp.value);
for SoapUI Pro Version 4.0.
I also have a Groovy script that writes the XML response to a file in another directory.
Currently, it uses a time/date stamp to name each XML Response file.
I would like to get the filename for each file that is read from the datasource, and use
the input filename to rename the output response XML files, so that I can tell which
response file corresponds to which input request file.
Also, I want to do this using a Groovy script.
Here is a copy of my current Groovy script that uses a time/date stamp to name the files:
date = new Date();
dateFormat = new java.text.SimpleDateFormat('MM-dd-yyyy');
dateStamp = dateFormat.format(date);
createFolder = new File("c:/Output/Responses " + dateStamp);
createFolder.mkdir();
time = new Date();
timeFormat = new java.text.SimpleDateFormat("HH.mm.ss.SS");
timeStamp = timeFormat.format(time);
def FileName = new PrintWriter( new FileWriter( "c:/Output/Responses " + dateStamp + "/" + dateStamp + " " + timeStamp + " response.xml.txt" ));
def ResponseMessage = testRunner.testCase.testSteps["Test Request"].testRequest.response.contentAsString;
def request = testRunner.testCase.getTestStepByName( "Test Request" );
def req = request.getProperty( "Request" );
def resp = request.getProperty( "Response" );
FileName.print( resp.value );
FileName.flush();
FileName.close();
log.info( resp.value);