Hope you all have used/ aware of the IntelliSense (Intelligent Code
Completion) which has been a feature only available for SoapUI NG Users
(version >1.3), which is no way realized by SoapUI Open Source/ Pro
users. To brief about the feature – “As you type code, available methods and
parameters are displayed in a drop-down and can be selected to speed up code
entry”.
|
Code Completion:
![]() |
|
Work around:
|
Solution:
For instance, if we need to know the method names supported
by testRunner object, we just need to append “.metaClass.methods*.name.unique().sort()” and
print to see the results in the logs.
Example 1:
log.info testRunner.metaClass.methods*.name.unique().sort()
Results in log:
Mon Jan 04 04:41:10 EST 2016:INFO:[cancel, equals, fail, getClass, getLog, getReason, getResults, getRunContext, getStartTime, getStatus, getTestCase, getTestRunnable, getTimeTaken, gotoStep, gotoStepByName, hashCode, isRunning, notify, notifyAll, runTestStep, runTestStepByName, setMockRunContext, setRunContext, start, toString, wait, waitUntilFinished]
This almost does the half of Code Completion feature’s work.
Just an another example, if we need to see the method names supported by XmlHolder
class (which is all the time preferred for XML Parsing),
Example 2:
import com.eviware.soapui.support.XmlHolder
log.info XmlHolder.metaClass.methods*.name.unique().sort()
Results in log:
Mon Jan 04 05:01:03 EST 2016:INFO:[clear, containsKey, containsValue, declareNamespace, entrySet, equals, get, getClass, getDomNode, getDomNodes, getNamespaces, getNodeValue, getNodeValues, getPrettyXml, getXml, getXmlObject, hashCode, isEmpty, keySet, notify, notifyAll, put, putAll, remove, removeDomNodes, setNodeValue, size, toString, updateProperty, values, wait]
Technical Description:
The solution is achieved through the Groovy language’s
native MetaClass
Interface. A MetaClass interface within Groovy (GDK/ GRE) defines
the behavior of any given Groovy or Java class. It would list what methods are
available for a groovy class; in turn the user can call those methods.
The above tweak will just give the method names.
Additionally, if you would like to see the method’s return type and arguments,
you should append “.metaClass.methods*.
unique().sort()” to the respective object/ class. This would return
as “public long com.eviware.soapui.impl.wsdl.panels.support.AbstractMockTestRunner.getStartTime()” instead of just “getStartTime”.
I hope this would one way or another give us a hint to
proceed further on scripting if you are not having the code completion feature.
Hope this gives a good start for your groovy scripting in SoapUI.


No comments:
Post a Comment
Leave out your valuable feedback's here!!!!!!