deepesh_jain
14 years agoFrequent Contributor
Help in using functions/methods in Groovy scripts!
Hello,
I have testbed which consists of 7 test cases. The first test case is just the launcher test case which consits of Master_launcher script. This reads the properties file and calls other test cases. The other test cases (TC1, TC2 etc..) have multiple test steps, with a combination of SOAP requests and other groovy scripts. I have disabled all the steps except the last. When I call the TC1 from launcher test case, it directly calls the last script, which reads the input file name passed from launcher script as a global property and populates the request xml of the soap request test step and submits the request. So far so good. However, once i get the response, i call another script within the same test case to perform validations. Due to amount of validations involved, I created some groovy functions and it worked fine till few days ago. But now i get errors during compilation. My test bed structure is something like this:
Test Suite System Test
...|---> Test Case Master Launcher
................|---> Test Step Launcher Script
...|---> Test Case 1
................|---> Validation Script (disabled)
................|---> Soap Request (disabled)
................|---> Script 1 (Enabled)
...|---> Test Case 2
................|---> Validation Script (disabled)
................|---> Soap Request (disabled)
................|---> Script 2 (Enabled)
...|---> Test Case 3
................|---> Validation Script (disabled)
................|---> Soap Request (disabled)
................|---> Script 3 (Enabled)
.
.
.
My Validation Script is something like this:
The exception i get is:
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
Script21.groovy: 30: Unknown type: METHOD_DEF at line: 30 column: 3. File: Script21.groovy @ line 30, column 3.
def setMessage (code, type, itext, list)
^
org.codehaus.groovy.antlr.ASTParserException: Unknown type: METHOD_DEF at line: 30 column: 3. File: Script21.groovy @ line 30, column 3.
at org.codehaus.groovy.antlr.AntlrParserPlugin.buildAST(AntlrParserPlugin.java:211)
at org.codehaus.groovy.control.SourceUnit.convert(SourceUnit.java:287)
at org.codehaus.groovy.control.CompilationUnit$8.call(CompilationUnit.java:591)
at org.codehaus.groovy.control.CompilationUnit.applyToSourceUnits(CompilationUnit.java:814)
at org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(CompilationUnit.java:511)
at org.codehaus.groovy.control.CompilationUnit.processPhaseOperations(CompilationUnit.java:487)
at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:464)
at groovy.lang.GroovyClassLoader.doParseClass(GroovyClassLoader.java:298)
at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:279)
at groovy.lang.GroovyShell.parseClass(GroovyShell.java:727)
at groovy.lang.GroovyShell.parse(GroovyShell.java:739)
at groovy.lang.GroovyShell.parse(GroovyShell.java:766)
at groovy.lang.GroovyShell.parse(GroovyShell.java:757)
at com.eviware.soapui.support.scripting.groovy.SoapUIGroovyScriptEngine.compile(SoapUIGroovyScriptEngine.java:141)
at com.eviware.soapui.support.scripting.groovy.SoapUIGroovyScriptEngine.run(SoapUIGroovyScriptEngine.java:90)
at com.eviware.soapui.impl.wsdl.teststeps.WsdlGroovyScriptTestStep.run(WsdlGroovyScriptTestStep.java:148)
at com.eviware.soapui.impl.wsdl.panels.teststeps.GroovyScriptStepDesktopPanel$RunAction$1.run(GroovyScriptStepDesktopPanel.java:274)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: org.codehaus.groovy.antlr.ASTRuntimeException: Unknown type: METHOD_DEF at line: 30 column: 3
at org.codehaus.groovy.antlr.AntlrParserPlugin.unknownAST(AntlrParserPlugin.java:2938)
at org.codehaus.groovy.antlr.AntlrParserPlugin.expressionSwitch(AntlrParserPlugin.java:1840)
at org.codehaus.groovy.antlr.AntlrParserPlugin.expression(AntlrParserPlugin.java:1519)
at org.codehaus.groovy.antlr.AntlrParserPlugin.expression(AntlrParserPlugin.java:1515)
at org.codehaus.groovy.antlr.AntlrParserPlugin.statement(AntlrParserPlugin.java:1144)
at org.codehaus.groovy.antlr.AntlrParserPlugin.statementListNoChild(AntlrParserPlugin.java:1165)
at org.codehaus.groovy.antlr.AntlrParserPlugin.statementList(AntlrParserPlugin.java:1153)
at org.codehaus.groovy.antlr.AntlrParserPlugin.statement(AntlrParserPlugin.java:1083)
at org.codehaus.groovy.antlr.AntlrParserPlugin.tryStatement(AntlrParserPlugin.java:1448)
at org.codehaus.groovy.antlr.AntlrParserPlugin.statement(AntlrParserPlugin.java:1132)
at org.codehaus.groovy.antlr.AntlrParserPlugin.convertGroovy(AntlrParserPlugin.java:253)
at org.codehaus.groovy.antlr.AntlrParserPlugin.buildAST(AntlrParserPl
I have testbed which consists of 7 test cases. The first test case is just the launcher test case which consits of Master_launcher script. This reads the properties file and calls other test cases. The other test cases (TC1, TC2 etc..) have multiple test steps, with a combination of SOAP requests and other groovy scripts. I have disabled all the steps except the last. When I call the TC1 from launcher test case, it directly calls the last script, which reads the input file name passed from launcher script as a global property and populates the request xml of the soap request test step and submits the request. So far so good. However, once i get the response, i call another script within the same test case to perform validations. Due to amount of validations involved, I created some groovy functions and it worked fine till few days ago. But now i get errors during compilation. My test bed structure is something like this:
Test Suite System Test
...|---> Test Case Master Launcher
................|---> Test Step Launcher Script
...|---> Test Case 1
................|---> Validation Script (disabled)
................|---> Soap Request (disabled)
................|---> Script 1 (Enabled)
...|---> Test Case 2
................|---> Validation Script (disabled)
................|---> Soap Request (disabled)
................|---> Script 2 (Enabled)
...|---> Test Case 3
................|---> Validation Script (disabled)
................|---> Soap Request (disabled)
................|---> Script 3 (Enabled)
.
.
.
My Validation Script is something like this:
import ....
import ....
import ....
import ....
log.info "Inside Validation Script";
PrintWriter pw = new PrintWriter(new FileWriter(new File("myfile.log"), true));
pw.println("STARTING XML VALIDATION");
try {
inputData = context.inputData;
def varMessage = [];
//variable declaration
.
.
def setFunction (code, type, itext, list)
{
def temp = [:];
temp["MessageCode"] = code ;
temp["MessageType"] = type ;
temp["MessageText"] = itext ;
list << temp;
}
setFunction (inputData[0,1],inputData[0,2],inputData[0,3], varMessage);
} catch (Exception E)
{
log.info "Caught Exception $E";
}
The exception i get is:
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
Script21.groovy: 30: Unknown type: METHOD_DEF at line: 30 column: 3. File: Script21.groovy @ line 30, column 3.
def setMessage (code, type, itext, list)
^
org.codehaus.groovy.antlr.ASTParserException: Unknown type: METHOD_DEF at line: 30 column: 3. File: Script21.groovy @ line 30, column 3.
at org.codehaus.groovy.antlr.AntlrParserPlugin.buildAST(AntlrParserPlugin.java:211)
at org.codehaus.groovy.control.SourceUnit.convert(SourceUnit.java:287)
at org.codehaus.groovy.control.CompilationUnit$8.call(CompilationUnit.java:591)
at org.codehaus.groovy.control.CompilationUnit.applyToSourceUnits(CompilationUnit.java:814)
at org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(CompilationUnit.java:511)
at org.codehaus.groovy.control.CompilationUnit.processPhaseOperations(CompilationUnit.java:487)
at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:464)
at groovy.lang.GroovyClassLoader.doParseClass(GroovyClassLoader.java:298)
at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:279)
at groovy.lang.GroovyShell.parseClass(GroovyShell.java:727)
at groovy.lang.GroovyShell.parse(GroovyShell.java:739)
at groovy.lang.GroovyShell.parse(GroovyShell.java:766)
at groovy.lang.GroovyShell.parse(GroovyShell.java:757)
at com.eviware.soapui.support.scripting.groovy.SoapUIGroovyScriptEngine.compile(SoapUIGroovyScriptEngine.java:141)
at com.eviware.soapui.support.scripting.groovy.SoapUIGroovyScriptEngine.run(SoapUIGroovyScriptEngine.java:90)
at com.eviware.soapui.impl.wsdl.teststeps.WsdlGroovyScriptTestStep.run(WsdlGroovyScriptTestStep.java:148)
at com.eviware.soapui.impl.wsdl.panels.teststeps.GroovyScriptStepDesktopPanel$RunAction$1.run(GroovyScriptStepDesktopPanel.java:274)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: org.codehaus.groovy.antlr.ASTRuntimeException: Unknown type: METHOD_DEF at line: 30 column: 3
at org.codehaus.groovy.antlr.AntlrParserPlugin.unknownAST(AntlrParserPlugin.java:2938)
at org.codehaus.groovy.antlr.AntlrParserPlugin.expressionSwitch(AntlrParserPlugin.java:1840)
at org.codehaus.groovy.antlr.AntlrParserPlugin.expression(AntlrParserPlugin.java:1519)
at org.codehaus.groovy.antlr.AntlrParserPlugin.expression(AntlrParserPlugin.java:1515)
at org.codehaus.groovy.antlr.AntlrParserPlugin.statement(AntlrParserPlugin.java:1144)
at org.codehaus.groovy.antlr.AntlrParserPlugin.statementListNoChild(AntlrParserPlugin.java:1165)
at org.codehaus.groovy.antlr.AntlrParserPlugin.statementList(AntlrParserPlugin.java:1153)
at org.codehaus.groovy.antlr.AntlrParserPlugin.statement(AntlrParserPlugin.java:1083)
at org.codehaus.groovy.antlr.AntlrParserPlugin.tryStatement(AntlrParserPlugin.java:1448)
at org.codehaus.groovy.antlr.AntlrParserPlugin.statement(AntlrParserPlugin.java:1132)
at org.codehaus.groovy.antlr.AntlrParserPlugin.convertGroovy(AntlrParserPlugin.java:253)
at org.codehaus.groovy.antlr.AntlrParserPlugin.buildAST(AntlrParserPl