I'm in the initial stage of learning Groovy with SoapUI Pro. So I started writing simple script in Groovy Teststep editor as shown below
class Hello {
static void main(String args[]) {
log.info("Welcome");
}
}
When I execute this script by clicking on the "Run" button from SoapUI Pro, it is throwing the following error message.
Error:
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: Script16.groovy: 5: unexpected token: [ @ line 5, column 30. static void main(String args[]) ^ org.codehaus.groovy.syntax.SyntaxException: unexpected token: [ @ line 5, column 30. at org.codehaus.groovy.antlr.AntlrParserPlugin.transformCSTIntoAST(AntlrParserPlugin.java:139) at org.codehaus.groovy.antlr.AntlrParserPlugin.parseCST(AntlrParserPlugin.java:107) at org.codehaus.groovy.control.SourceUnit.parse(SourceUnit.java:236) at org.codehaus.groovy.control.CompilationUnit$1.call(CompilationUnit.java:163) at org.codehaus.groovy.control.CompilationUnit.applyToSourceUnits(CompilationUnit.java:839) at org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(CompilationUnit.java:544) at org.codehaus.groovy.control.CompilationUnit.processPhaseOperations(CompilationUnit.java:520) at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:497) at groovy.lang.GroovyClassLoader.doParseClass(GroovyC lassLoader.java:306) at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:287) at groovy.lang.GroovyShell.parseClass(GroovyShell.java:731) at groovy.lang.GroovyShell.parse(GroovyShell.java:743) at groovy.lang.GroovyShell.parse(GroovyShell.java:770) at groovy.lang.GroovyShell.parse(GroovyShell.java:761) at com.eviware.soapui.support.scripting.groovy.SoapUIGroovyScriptEngine.compile(SoapUIGroovyScriptEngine.java:148) at com.eviware.soapui.support.scripting.groovy.SoapUIGroovyScriptEngine.run(SoapUIGroovyScriptEngine.java:93) at com.eviware.soapui.support.scripting.groovy.SoapUIProGroovyScriptEngineFactory$SoapUIProGroovyScriptEngine.run(SourceFile:89) at com.eviware.soapui.impl.wsdl.teststeps.WsdlGroovyScriptTestStep.run(WsdlGroovyScriptTestStep.java:149) at com.eviware.soapui.impl.wsdl.panels.teststeps.GroovyScriptStepDesktopPanel$RunAction$1.run(GroovyScriptStepDesktopPanel.java:274) at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) at java.util.concurr ent.ThreadPoolExecutor$Worker.run(Unknown Source) at java.lang.Thread.run(Unknown Source) Caused by: Script16.groovy:5:30: unexpected token: [ at org.codehaus.groovy.antlr.parser.GroovyRecognizer.parameterDeclaration(GroovyRecognizer.java:8413) at org.codehaus.groovy.antlr.parser.GroovyRecognizer.parameterDeclarationList(GroovyRecognizer.java:7397) at org.codehaus.groovy.antlr.parser.GroovyRecognizer.variableDefinitions(GroovyRecognizer.java:2311) at org.codehaus.groovy.antlr.parser.GroovyRecognizer.declaration(GroovyRecognizer.java:2140) at org.codehaus.groovy.antlr.parser.GroovyRecognizer.classField(GroovyRecognizer.java:5936) at org.codehaus.groovy.antlr.parser.GroovyRecognizer.classBlock(GroovyRecognizer.java:5236) at org.codehaus.groovy.antlr.parser.GroovyRecognizer.classDefinition(GroovyRecognizer.java:1942) at org.codehaus.groovy.antlr.parser.GroovyRecognizer.typeDefinitionInternal(GroovyRecognizer.java:1822) at org.codehaus.groovy.antlr.parser.GroovyRecognizer.statement(GroovyR ecognizer.java:1305) at org.codehaus.groovy.antlr.parser.GroovyRecognizer.compilationUnit(GroovyRecognizer.java:757) at org.codehaus.groovy.antlr.AntlrParserPlugin.transformCSTIntoAST(AntlrParserPlugin.java:130) ... 21 more 1 error
I'm not sure what wrong did I do and what I have to do for solving this issue.
Thanks
Karunagara Pandi
Groovy is 99% code-compatible with Java. So you can use straight up Java in a Groovy script.
Your problem is that you are declaring a method main
. In a SoapUI Groovy Script step you do not declare a method. You just start writing code. See Groovy documentation for additional information.
So your script should be just:
log.info("Welcome");
No class
, no static void main
, just that one liner!
You've bad syntax.
Replace:
String args[]
with:
String[] args
or simply:
args
UPDATE (log)
MPE is thrown because You don't have a declaration for log field. Try adding the following import:
import groovy.util.logging.Slf4j
and annotate the @Slf4j annotation. Also see here . Don't know how logging works exactly with SoapUI.
class Hello {
def log = this.log;
void main(String[] args) {
log.info("Welcome");
}
}
Out: Wed Oct 26 12:22:35 EEST 2016:INFO:Welcome
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.