Forum Discussion
5 Replies
- ChrisAdamsSuper Contributor
Hi,
This is doable. But, you've not provided much detail or how you're trying to call the class. So instead, I've made a simple example that does nothing more than log a message.
Firstly, Groovy scripts/classes need to be added to the ReadyAPI/SoapUI install folders. SoapUI scans the scripts folders for new/changed scripts.
On my machine, I added these to.... \\\SmartBear\ReadyAPI-3.3.0\bin\scripts\groovyScripts
The filename is the name of the class with the .groovy extension. In this case, I have a file in the above folder named, "MyTearDownClass.groovy".
Below are the contents of that file...package groovyScripts class MyTearDownClass { def logThePassedInMessge(log, message) { log.info(message); } }The package is important and must match the folder structure below \\\SmartBear\ReadyAPI-3.3.0\bin\scripts\
You can see if SoapUI can see and detect changes in your file by making a small change in your file and saving. Then switch to SoapUI and look at SoapUI Log
OK, now go to the Teardown script, my example is below....
tearDownObject = new groovyScripts.MyTearDownClass(); tearDownObject.logThePassedInMessge(log, "Hello from TearDown!");And by either clicking the Teardown 'go' button or just the test case as a whole, I can see that this works by looking at the Script Log tab....
- jwasiakNew Contributor
I'm using SoapUI 5.7.
I have followed your sample and added the script under the same coresponding location here:
C:\Program Files\SmartBear\SoapUI-5.7.0\bin\scripts\groovyScripts
Then in newly created TestCase teardown script I added your code which at run gives me this error:
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: Script2.groovy: 1: unable to resolve class groovyScripts.MyTearDownClass @ line 1, column 18. tearDownObject = new groovyScripts.MyTearDownClass(); ^ org.codehaus.groovy.syntax.SyntaxException: unable to resolve class groovyScripts.MyTearDownClass @ line 1, column 18. at org.codehaus.groovy.ast.ClassCodeVisitorSupport.addError(ClassCodeVisitorSupport.java:262) at- ChrisAdamsSuper Contributor
The above example was built using ReadyAPI 3.40.2.
I have SoapUI 5.5.0, let me try there and I'll get back to you.
- ChrisAdamsSuper Contributor
Hi,
Last one, it's almost like they've disabled this in more recent versions. See this... https://www.soapui.org/docs/scripting-and-properties/scripting-and-the-script-library/