Try this in the Groovy Script step.
testRunner.testCase.testSteps.each{k, v ->
if(k in ['step1', 'step2'])
v.cancel()
}
where step1
and step2
are the steps you want to skip.
Config way log4j.xml
There is already a file for Groovy log configured in SOAPUI log4j configuration file.
In SOAPUI_HOME\bin\soapui-log4j.xml:
<appender name="GLOBAL_GROOVY_LOG" class="org.apache.log4j.FileAppender">
<errorHandler class="org.apache.log4j.helpers.OnlyOnceErrorHandler"/>
<param name="File" value="${soapui.logroot}global-groovy.log"/>
<param name="Threshold" value="DEBUG"/>
<param name="Append" value="true"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d %-5p [%c{1}] %m%n"/>
</layout>
</appender>
<logger name="groovy.log">
<level value="INFO" />
<appender-ref ref="GLOBAL_GROOVY_LOG" />
</logger>
A possible way is to add another custom FileAppender
in this config file. If you change this file remember to restart SOAPUI in order that it can load the changes.
Something like this can do the trick:
<appender name="GLOBAL_GROOVY_LOG" class="org.apache.log4j.FileAppender">
<errorHandler class="org.apache.log4j.helpers.OnlyOnceErrorHandler"/>
<param name="File" value="${soapui.logroot}global-groovy.log"/>
<param name="Threshold" value="DEBUG"/>
<param name="Append" value="true"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d %-5p [%c{1}] %m%n"/>
</layout>
</appender>
<appender name="MYLOG_CUSTOM" class="org.apache.log4j.FileAppender">
<errorHandler class="org.apache.log4j.helpers.OnlyOnceErrorHandler"/>
<param name="File" value="/absoultePath/yourlogFile.txt"/>
<param name="Threshold" value="DEBUG"/>
<param name="Append" value="true"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d %-5p [%c{1}] %m%n"/>
</layout>
</appender>
<logger name="groovy.log">
<level value="INFO" />
<appender-ref ref="GLOBAL_GROOVY_LOG" />
<appender-ref ref="MYLOG_CUSTOM" />
</logger>
Dinamically using Groovy
However it seems that you want to do it dynamically using Groovy script, hence you can use the follow code to get <logger name="groovy.log">
and add a FileAppender
to it; in order that you can save the logs in a custom file:
import org.apache.log4j.Logger
import org.apache.log4j.PatternLayout
import org.apache.log4j.RollingFileAppender
// get the groovy logger by name
def groovyLogger = Logger.getLogger('groovy.log')
// pattern Layout
PatternLayout layout = new PatternLayout("%d{ISO8601} [%t] %-5p %c %x - %m%n")
// create a file appender
RollingFileAppender fileAppender = new RollingFileAppender(layout, "/absolutePath/myLog.txt")
groovyLogger.addAppender(fileAppender)
log.info 'someText to the logger'
NOTE: If you don't use an absolute path in FileAppender
the log file is saved relative to *SOAPUI_HOME\bin*
When you configure this the rest of logs in Groovy testSteps will be appended to this file. If you want to get only the log for a specific Groovy testStep then you can simply remove the appender at the end of the script:
groovyLogger.removeAppender(fileAppender);
UPDATE:
From you comment: I want to store output for each run, and if I am executing this again it should rewrite the file.
So you want to store output for each run... but you want to overwrite the file if you execute again? This is contradictory isn't?
If you want to overwrite the file instead of append the content you can use setAppend(false)
:
fileAppender.setAppend(false)
fileAppender.activateOptions()
groovyLogger.addAppender(fileAppender)
Best Answer
SoapUI allows to write inline script with in soap request and do not have to write a Groovy Script test step separately.
All you need to do is modify your
timestamp
request element to as below: