使用 groovy 脚本从 SoapUI 中的测试用例捕获脚本日志

Capturing Script logs from a test case in SoapUI using groovy script

谁能帮我写一个脚本,使用 groovy 脚本从 soap UI 的测试用例中捕获脚本日志。

取自此处:https://community.smartbear.com/t5/SoapUI-NG/Export-http-log-to-a-file-with-groovy-script/td-p/198

请注意,脚本日志仅记录 log.info 记录的内容。此外,当您 运行 整个测试用例时,日志只会放在脚本日志中,而不是当您 运行 手动 groovy 脚本时。

def logArea = com.eviware.soapui.SoapUI.logMonitor
if( logArea != null )
{
   def ix = logArea.indexOfTab( "Script log" );
   if( ix >= 0 )
   {
      def logPanel = logArea.getComponentAt( ix )
      def model = logPanel.logList.model
      if( model.size > 0 )
      {
         def out = new java.io.PrintWriter( "C:/pathtofile/myfile.log" )

         for( c in 0..(model.size-1) )
            out.println( model.getElementAt( c ))

         out.close()
      }
   }
}

@canpan 以下代码对我有用,感谢您一直以来的帮助

'

def logArea = com.eviware.soapui.SoapUI.logMonitor.getLogArea("script log")
def LogFile = new File ("I:/SOAP UI/AutomationFramework/script.txt")
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")
        }
    }
}

'