harry21
8 years agoOccasional Contributor
Getting MissingMethodException while calling Groovy class in a script
Below is the groovy script which I would like to convert into reusable Groovy class
def resp = context.testCase.getTestStepByName(retrieveSequenceNumberAfter).getPropertyValue("ResponseAsXml") def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context ) def holder = groovyUtils.getXmlHolder(resp) def transid = holder.getNodeValue("Results/ResultSet/Row/transaction_id") log.info transid
I've created a Groovy class library with the method validatetransid as in following code in it:
package com.Linos.readyapi.util.trans.transaction class TransactionID { def context def log def validatetransid(String stepName) { def resp = context.testCase.getTestStepByName(stepName).getPropertyValue("ResponseAsXml") def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context ) def holder = groovyUtils.getXmlHolder(resp) def transid = holder.getNodeValue("Results/ResultSet/Row/transaction_id") log.info transid } }
I'm trying to create the object of class and use the methods anywhere in the SoapUI projects as below:
define transid = new TransactionID(context:context, log:log) transid.validatetransid('retrieveSequenceNumberAfter')
With the above code, I'm getting the following exception.. Please advise where my code goes wrong?
groovy.lang.MissingMethodException: No signature of method: Script17.define() is applicable for argument types: (com.Linos.readyapi.util.trans.transaction.TransactionID) values: [com.Linos.readyapi.util.trans.transaction.TransactionID@228bb11d] Possible solutions: find(), find(groovy.lang.Closure), print(java.lang.Object), main([Ljava.lang.String;), print(java.lang.Object), print(java.io.PrintWriter)
Below is the class for Script Library:
package com.linos.readyapi.util.transaction class Utility { static def getData(response, element) { assert response, 'response is empty' def pXml = new XmlSlurper().parseText(response) pXml.'**'.findAll {it.name() == element} } }
In the Script Assertion, use below statements:
import static com.linos.readyapi.util.transaction.Utility.getData log.info "Details from response: ${getData(context.response, 'transaction_id')}"