Contributions
Re: How to create a Groovy JAR file for SoapUI using Eclipse
I can dispense with this work-around 'solution' if there is a way to get to the com.eviware.soapui.SoapUI.logMonitor object via any of the references that are already present in the soapUI TestCase teardown script context - there are four I know of - context, testRunner, testCase and log. Since I already have these Properties in my own customScripts Package of groovy classes, then I should try to use one of them to get to the desired logMonitor object if I can. Is it possible to get to logMonitor via any of these four references? I would think this could be done either using the log or the testRunner reference, or maybe using the context reference. I'm not sure where to start to get the answer.2.1KViews0likes0CommentsRe: How to create a Groovy JAR file for SoapUI using Eclipse
Ok - I have a work-around, if not a solution, for the problem. The error complains that "com.eviware....." is not a property of my teardownScripts class. So, I created a reference to com.eviware.soapui.SoapUI.logMonitor and I pass that as a property to my custom teardownScripts class, like this (from inside the soapUI TestCase teardown): def [b]logMon[/b] = com.eviware.soapui.SoapUI.logMonitor def tdscript = new customScripts.teardownScripts(log, context, testRunner, testCase, [b]logMon[/b]) tdscript.Teardown() Now, inside my teardownScripts class, I added the logMon Property (to both the class definition and to its constructor), and I use it to invoke desired methods on the com.eviware.soapui.SoapUI.logMonitor object, instead of trying to import com.eviware.soapui.SoapUI.logMonitor and trying to reference it directly, which produces the error that "com" is not a valid property of my class. The JAR file I create for the SoapUI Free version to use, which contains my entire package of custom scripts, now works perfectly. And both the Pro and the Free version can use the same central groovy script library (albeit from different sources - Pro from the source library itself, and Free from the JAR file created from that selfsame source library). This is important, since we don't want to produce test automation that won't run on the Free version. This is pretty silly, really. In the Free version you should be able to simply import com.eviware.soapui.SoapUI.logMonitor and use it from inside a groovy script that is JAR'ed up and placed in the ...\bin\ext\ directory. You shouldn't have to explicitly make it a Property of your class and pass it in, as I am having to do here. If someone has a real solution, I'm sure plenty of people would appreciate knowing about it, since I can't be the only person trying to produce automation that will run seamlessly on both the Free and Pro versions of SoapUI.2.1KViews0likes0CommentsRe: How to create a Groovy JAR file for SoapUI using Eclipse
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? 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") } } }2.1KViews0likes0CommentsRe: How to create a Groovy JAR file for SoapUI using Eclipse
The SoapUI.logMonitor object I am invoking does exist in the source you linked. I can directly run the operational code in my Teardown() method, doing so from the soapUI TestCase teardown script, and I get no errors. The com.eviware.soapui.SoapUI.logMonitor object is found, and the logging I ask it to perform works as expected. I just tried this again, in the Free version, and it works with no errors at all. All the operational code in my Teardown() method, including the use of the com.eviware.soapui.SoapUI.logMonitor object, works exactly as expected, when I run it directly inside the TestCase Teardown Script. But when I try to run it from the JAR file as a method inside a class I get the error that says "com" is not a valid property for the Teardown() method.2.1KViews0likes0CommentsCan'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") } } } } }2KViews0likes3CommentsRe: How to create a Groovy JAR file for SoapUI using Eclipse
"no such Property - com - for class customScripts...." - hmmmm Does this mean that "com" has to be added as a Property to my class? Like "log", "context", "testCase" and "testSuite" are Properties and are included in my constructor? How do I add the com property, since the location from where I am calling this particular TearDown() method doesn't have a "com" Property? Somehow, I should be able to tell my custom scripts that com is a valid Property, and I should be able to use com. ?? in my scripts.2.1KViews0likes0CommentsRe: How to create a Groovy JAR file for SoapUI using Eclipse
Hi Rao, I get no errors in the compilation of the groovy scripts nor in the creation of the JAR file. I do place the JAR file in the ....\bin\ext\ dir and restart SoapUI Free - but the same error occurs. Here is the source code so you can see what I am doing: Here is a call I make to my custom Teardown() method, from inside the soapUI TestCase Teardown Script: def tdscript = new customScripts.teardownScripts(log, context, testRunner, testCase) tdscript.Teardown() Here is the groovy script itself: 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") } } } } } Here is the error I get when trying to run the TestCase in soapUI Free after compiling, building the JAR, placing it in ...\bin\ext\ and restarting soapUI Free: 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. What am I doing wrong? This all works perfectly in soapUI Pro with the groovy source code package folder (customScripts) placed in the ....\bin\scripts\ dir. But in the Free version it can't seem to find the "com" property.5.9KViews0likes0CommentsRe: How to create a Groovy JAR file for SoapUI using Eclipse
Hi Rao, This is very helpful - I can create a JAR file - and I think I have only one minor obstacle now. When I try to run a groovy script from the JAR file collection of scripts, I get the error "groovy.lang.MissingPropertyException: No such property: com for class: customScripts.teardownScripts" In my "teardownScripts" groovy script, I am using this: def logMon = com.eviware.soapui.SoapUI.logMonitor Evidently, the "com" property isn't being found or defined. I tried importing it with this in my groovy script: package customScripts; import com.eviware.soapui.SoapUI.logMonitor.*; class teardownScripts { ..... And then I re-created the JAR file and placed it in the correct path for SoapUI Free, but the same error persists. How can I resolve the error which seems to indicate that the com property (com.eviware.soapui.SoapUI.logMonitor) isn't defined? Thanks so much, Rao!5.9KViews0likes0CommentsRe: How to create a Groovy JAR file for SoapUI using Eclipse
Hi Rao, The links you provided help somewhat, but I am still stuck on the steps needed to actually create the correct JAR file for Groovy scripts. These scripts are defined as classes with static methods, and all the Groovy classes are declared as belonging to the package "customScripts". Everything works perfectly in SoapUI Pro - I simply place the "customScripts" folder in the ..../bin/scripts/ dir and SoapUI Pro sees the scripts and executes them. Now - I just need to create the correct JAR file containing the same Groovy scripts so I can place this in the ..../bin/ext/ dir of SoapUI Free so it too will be able to invoke the scripts. Right now I am stuck at the point where Eclipse Kepler demands that I set the Package for my Groovy project to something from a drop-down list - and I have little idea which choice from the list would be the right one. Also - I want to keep the "customScripts" package name, but Eclipse seems to be uncooperative. I know I am a real junior Eclipse and JAR file beginner. I just need some guidance on how to choose the right package for my Eclipse Groovy project, generate the right kind of JAR file, and then I can test it out on SoapUI Free. My Groovy scripts use the testRunner, testCase, log and context objects in SoapUI, and some of the methods take a parameter or two. They are pretty simple. I just need to understand how to generate a JAR file that has all the right dependencies for Groovy, SoapUI, etc.5.9KViews0likes0Comments