Exporting the Script Log to an external file
- 8 years ago
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!