Forum Discussion

HP-Plano-TX-Soa's avatar
HP-Plano-TX-Soa
Occasional Contributor
11 years ago

Can't use com.eviware objects from inside groovy JAR file?

I have a central groovy script library in the form of a JAR file, which I place in the ....\bin\ext\ directory of the soapUI Free version. Within this JAR file I have a "customScripts" Package which I created, which contains a number of classes with their methods. In one of these classes I have a method, Teardown(). Within this method I attempt to use a soapUI com object, "com.eviware.soapui.SoapUI.logMonitor".

However, whenever I attempt to run a testCase which uses this central script library and tries to call the Teardown() method, I get the following error:

groovy.lang.MissingPropertyException: No such property: com for class: customScripts.teardownScripts
Possible solutions: log
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:50)
at org.codehaus.groovy.runtime.callsite.GetEffectivePogoPropertySite.getProperty(GetEffectivePogoPropertySite.java:86)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callGroovyObjectGetProperty(AbstractCallSite.java:231)
at customScripts.teardownScripts.Teardown(teardownScripts.groovy:86)
at customScripts.teardownScripts$Teardown.call(Unknown Source)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:42)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:112)
at Script1.run(Script1.groovy:2)
at com.eviware.soapui.support.scripting.groovy.SoapUIGroovyScriptEngine.run(SoapUIGroovyScriptEngine.java:96)
at com.eviware.soapui.impl.wsdl.testcase.WsdlTestCase.runTearDownScript(WsdlTestCase.java:953)
at com.eviware.soapui.impl.wsdl.support.AbstractTestCaseRunner.runTearDownScripts(AbstractTestCaseRunner.java:203)
at com.eviware.soapui.impl.wsdl.support.AbstractTestCaseRunner.internalFinally(AbstractTestCaseRunner.java:184)
at com.eviware.soapui.impl.wsdl.support.AbstractTestCaseRunner.internalFinally(AbstractTestCaseRunner.java:43)
at com.eviware.soapui.impl.wsdl.support.AbstractTestRunner.run(AbstractTestRunner.java:163)
at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)

Line 86 in my groovy script is exactly the line where I reference the com.eviware.soapui.SoapUI.logMonitor object.


This all works fine in soapUI Pro - the entire "customScripts" groovy library works perfectly, as I place it in the ....\bin\scripts\ directory.

But the Free version can't use a com.eviware. object from within a groovy script, and complains with the error above.

I get no errors when I compile the groovy scripts and create the JAR file.

Why can't I use a com.eviware object from within a groovy script in my custom JAR file???

Here is a sample call I make from within a testCase teardown script:

def tdscript = new customScripts.teardownScripts(log, context, testRunner, testCase)
tdscript.Teardown()



Here is the source code for the class that contains the custom Teardown() method I am trying to run:

package customScripts;

import com.eviware.soapui.SoapUI.logMonitor.*;

class teardownScripts
{
def log
def context
def testRunner
def testCase

teardownScripts(log, context, testRunner, testCase)
{
this.log = log
this.context = context
this.testRunner = testRunner
this.testCase = testCase
}

def Teardown()
{
def testStep;
def tstype;
def tsname;
def myRequestStep;
def request;
def response;
def sts;

context.fileReader.close()

if (context.expand('${#TestCase#ScriptLogVerbose}') != "YES")
{
return
}

// Log the testCase name, status and all the testStep messages
//
def 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 ("\r\n\r\n" + "**** " + "$tsname: RAW REQUEST: " + request + "\r\n\r\n")
log.info ("\r\n\r\n" + "**** " + "$tsname: RAW RESPONSE: " + response + "\r\n\r\n")
}

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 = null
def logMon = [b]com[/b].eviware.soapui.SoapUI.logMonitor
if ( logMon != null ) {
logArea = [b]com[/b].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')
def 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")
}
}
}
}
}