In this Groovy Script example, lets see how can we capture the soapUI logs and save it into a file. At the bottom of soapUI, you might have noticed different tabs named soapUI log, http log, jetty log, error log, wsrm log, memory log and script log. Each tab will have the logs based on log category. For example, if you are invoking a Web Service request/ response, you will be able to see the web service request and response with the http headers under http tab. Same way if you have groovy script to on your soapUI test steps and if those groovy scripts are printing any dynamic values while test execution, you might also see that in the tab "script log". Lets see the below groovy script to capture the logs and save it into a text file.
//The below groovy script step is to capture the soapUI log area.
// "soapUI log" can be replaced with http log, jetty log, script log, error log etc based on the need.
def logArea = com.eviware.soapui.SoapUI.logMonitor.getLogArea( "soapUI log" );
//Below two lines of groovy script is to get the project directory, we will be saving the soapUI log contents on a file in that directory.
def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context)
def projectPath = groovyUtils.projectPath
def logFile = new File(projectPath + "\\soapUI-Logs-to-file.txt")
//This is the first line in the soapUI log file.
logFile.write("soapUI Logs In a file.\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 ))
}