Forum Discussion
HP-Plano-TX-Soa
13 years agoOccasional Contributor
Rao,
You can't place the class definition and the Teardown() method and all the source of the package "customScripts" inside the TestCase teardown and expect it to work. It's not a groovy script in that form - and SoapUI expects to see a groovy script in the TestCase teardown, not a full package declaration with class and methods, like you need to place in a JAR file.
You are way over-complicating the issue.
Here is what I can place in the TestCase teardown, and run, with no errors - note that the logMonitor object is seen just fine - so the question is why the same com.eviware object (or any com.
? object) can't be used from a groovy script that is packaged in a JAR file?
You can't place the class definition and the Teardown() method and all the source of the package "customScripts" inside the TestCase teardown and expect it to work. It's not a groovy script in that form - and SoapUI expects to see a groovy script in the TestCase teardown, not a full package declaration with class and methods, like you need to place in a JAR file.
You are way over-complicating the issue.
Here is what I can place in the TestCase teardown, and run, with no errors - note that the logMonitor object is seen just fine - so the question is why the same com.eviware object (or any com.
? object) can't be used from a groovy script that is packaged in a JAR file?if (context.expand('${#TestCase#ScriptLogVerbose}') != "YES")
{
return
}
// Log the testCase name, status and all the testStep messages
//
testCaseName = testRunner.testCase.name
log.info testCaseName
if ( testRunner.getStatus().toString() == 'FAILED' )
{
log.info ("$testCaseName has failed")
}
else
{
log.info ("$testCaseName has Passed")
}
for ( testStepResult in testRunner.getResults() )
{
testStep = testStepResult.getTestStep()
tstype = testStep.config.type
// log.info tstype
tsname = testStepResult.testStep.name
myRequestStep = testRunner.testCase.getTestStepByName("$tsname")
if ( tstype == "request" && myRequestStep.testRequest.messageExchange != null)
{
request = new String(myRequestStep.testRequest.messageExchange.rawRequestData)
response = new String(myRequestStep.testRequest.messageExchange.rawResponseData)
log.info ("$tsname: RAW REQUEST: " + request)
log.info ("$tsname: RAW RESPONSE: " + response)
}
sts = testStepResult.getStatus().toString()
log.info ("$tsname has status of: " + "$sts")
testStepResult.messages.each() { msg -> log.info (tsname + ": " + msg) }
}
if (context.expand('${#TestCase#SaveLogFiles}') != "YES")
{
return
}
// Give SoapUI script logging a chance to catch up before attempting to capture the script log to a file
sleep (5000)
// Save the TestCase Log, error log and script log to a combined log file
//
// "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( "script log" )
def path = context.expand('${#Project#Log_files_loc}')
def date = new Date()
def datefmt = new java.text.SimpleDateFormat('yyyy_MM_dd_kkmmss')
timestamp = datefmt.format(date)
log.info timestamp
def logFile = new File(path + testCaseName + "_" + timestamp + ".txt")
log.info (path + testCaseName + "_" + timestamp + ".txt")
logFile.write("============================= SCRIPT LOGS: ===============================\r\n\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")
// logFile.append("\r\n")
}
}
}