Exporting the Script Log to an external file
I would like to be able add a Groovy script in a Teardown Script from either Project, Test Suite, or Test Case or even in an Event handler that exports the "current" output of the Script Log to an external file.
I had opened a message about this in the past but the person who was "helping" me decided to stop helping me. That thread is at https://community.smartbear.com/t5/SoapUI-NG/Exporting-ReadyAPI-logs-to-an-external-file/td-p/128118
Basically what I was told was that because ReadyAPI! already logs all Script Log output to a file that I shouldn't have any need to do what I am doing but unfortunately not everyone's needs are the same.
I have tried something new from what was in my previous thread such as
timeStamp = System.currentTimeMillis() fileName = log.name new File("C:/MyFolder"+timeStamp+fileName).withWriter { writer -> writer.writeLine fileName }
My SoapUI project runs without error but nothing is created. I would prefer to do this without having to edit the log4j.xml file; I don't need a new file every time I run something but at some point my SoapUI project will be complete and other people will be running it and it would be beneficial if the Script Log output could live in the same working directory as the SoapUI project, which will not be the same every time for every project.
Hello there! This is interesting because I am almost using similar script you pointed in your earlier discussion and it works! Currently I am exporting all the script logs via Event Handler. I am capturing logs and exporting them to a file after entire test-suite runs. Also please note that log file derives its name from TestSuite Name.
My events are at TestSuite level
Clean up previous log entities - TestSuiteRunListener.beforeRun
//Clear Script Logs
com.eviware.soapui.SoapUI.logMonitor.getLogArea("Script log").clear()//## Get TestSuite name ##//
def TSName = testRunner.testSuite.name//Get LogFile directory and Construct LogFile
def LogFilePath = context.expand('${#Project#TestReportPath}')
def LogFile = TSName + "-Logs.txt"
LogFile = LogFilePath + LogFiledef LogFiles = new File(LogFile)
log.info "Clearing previous logs..."
LogFiles.delete()Write script logs to a file - TestSuiteRunListener.afterRun
def logArea = com.eviware.soapui.SoapUI.logMonitor.getLogArea( "Script log" )
//## Get TestSuite name ##//
def TSName = testRunner.testSuite.name//Get LogFile directory and Construct LogFile
def FileName = TSName + "-Logs.txt"
def LogFile = new File(context.expand('${#Project#TestReportPath}') + FileName)LogFile.write("Generating Script logs....\r\n")
if(logArea !=null)
{
def model = logArea.model
if(model.size > 0) {
for(c in 0..(model.size-1))
{
LogFile.append(model.getElementAt(c).toString() + "\r\n")
}
}
}Hope this helps!