Error Hunter
Error Hunter

Reputation: 1684

java.lang.InstantiationException error when executing class in Groovy Soap UI 5.4.0

trying to execute a Groovy script in SOAPUI 5.4.0

class MyClass {
// The three following fields are MANDATORY
def log 
def context
def testRunner

public  MyClass(log,context,testRunner){
    this.log = log 
    this.context = context
    this.testRunner = testRunner
    }
    def MyMethod(){log.info "Reference Groovy function file" }
}

class Call{

MyClass myClass = new MyClass();
myClass.MyMethod();

}

and receiving error i.e.

groovy.lang.GroovyRuntimeException: Failed to create Script instance for class: class MyClass. Reason: java.lang.InstantiationException: MyClass

same code was working in previous soap ui version , could you please help.

Error stack

*Tue May 29 15:43:08 IST 2018:ERROR:cannot get error line number!
Tue May 29 15:43:08 IST 2018:ERROR:java.lang.IllegalStateException: No match found
   java.lang.IllegalStateException: No match found
    at java.util.regex.Matcher.group(Matcher.java:536)
    at com.eviware.soapui.support.GroovyUtils.extractErrorLineNumber(GroovyUtils.java:128)
    at com.eviware.soapui.impl.wsdl.teststeps.WsdlGroovyScriptTestStep.run(WsdlGroovyScriptTestStep.java:163)
    at com.eviware.soapui.impl.wsdl.panels.teststeps.GroovyScriptStepDesktopPanel$RunAction$1.run(GroovyScriptStepDesktopPanel.java:250)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at java.lang.Thread.run(Thread.java:748)
Tue May 29 15:43:08 IST 2018:ERROR:groovy.lang.GroovyRuntimeException: Failed to create Script instance for class: class MyClass. Reason: java.lang.InstantiationException: MyClass
   groovy.lang.GroovyRuntimeException: Failed to create Script instance for class: class MyClass. Reason: java.lang.InstantiationException: MyClass
    at org.codehaus.groovy.runtime.InvokerHelper.createScript(InvokerHelper.java:464)
    at groovy.lang.GroovyShell.parse(GroovyShell.java:706)
    at groovy.lang.GroovyShell.parse(GroovyShell.java:742)
    at groovy.lang.GroovyShell.parse(GroovyShell.java:733)
    at com.eviware.soapui.support.scripting.groovy.SoapUIGroovyScriptEngine.compile(SoapUIGroovyScriptEngine.java:136)
    at com.eviware.soapui.support.scripting.groovy.SoapUIGroovyScriptEngine.run(SoapUIGroovyScriptEngine.java:87)
    at com.eviware.soapui.impl.wsdl.teststeps.WsdlGroovyScriptTestStep.run(WsdlGroovyScriptTestStep.java:141)
    at com.eviware.soapui.impl.wsdl.panels.teststeps.GroovyScriptStepDesktopPanel$RunAction$1.run(GroovyScriptStepDesktopPanel.java:250)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at java.lang.Thread.run(Thread.java:748)
   Caused by: java.lang.InstantiationException: MyClass
    at java.lang.Class.newInstance(Class.java:427)
    at org.codehaus.groovy.runtime.InvokerHelper.createScript(InvokerHelper.java:436)
    ... 10 more
   Caused by: java.lang.NoSuchMethodException: MyClass.<init>()
    at java.lang.Class.getConstructor0(Class.java:3082)
    at java.lang.Class.newInstance(Class.java:412)
    ... 11 more*

Upvotes: 2

Views: 2888

Answers (1)

Rao
Rao

Reputation: 21389

Create a Groovy Script test step and have the class and call to the method as shown below script:

class MyClass {
    def log 
    def context
    def testRunner

    def myMethod(){
        log.info "Reference Groovy function file" 
    }
}

//Call above class method as below
def myClassObject = [log: log, context: context, testRunner: testRunner] as MyClass
myClassObject.myMethod()

Upvotes: 2

Related Questions