Forum Discussion

jkrier's avatar
jkrier
Regular Contributor
8 years ago

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 ex...
  • New2API's avatar
    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 + LogFile

    def 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!