Adi Mor
Adi Mor

Reputation: 2175

Empty file when saving soapUI response

I'm using groovy script in soapUI. I want to save my response to file. I'm using the following script. The file is created, but it's content is empty.

//get dir target from property
def dirTarget = context.expand( '${#Project#SnapShotDirTarget}' )

def fileDir = new File(dirTarget);
if(!fileDir .exists()) {
   fileDir .mkdirs()
} 

def currentDate = new Date().format("yyyy-MM-dd hh:mm")
def fileName = "Snapshot - "+currentDate+".txt"
def resultsFile= new File(fileDir , context.expand( fileName) )

if(!resultsFile.exists()) {
    resultsFile.createNewFile();
}

resultsFile.append("Post URL:"+messageExchange.getEndpoint()+'\n' ); 
resultsFile.append("Request:"+'\n' ); 
resultsFile.append(messageExchange.getRequestContent()+'\n' ); 
resultsFile.append("Response:"+'\n' ); 
resultsFile.append(messageExchange.getResponseContent()+'\n' ); 

Upvotes: 0

Views: 403

Answers (1)

Joel Jonsson
Joel Jonsson

Reputation: 800

If you are running Windows the colon between the hour and minutes in the filename is going to cause some problems, since colon is not allowed in Windows file names.

When I tried running the script it created an empty file called "Snapshot - 2014-08-14 09" (everything after and including the colon is missing)

Changing the colon to something else makes the trick.

def currentDate = new Date().format("yyyy-MM-dd hh_mm")

The call to createNewFile is not necessary by the way. The append call will create the file if it doesn't exist.

Upvotes: 1

Related Questions