Alagu Pandi Alagu Pandi - 1 year ago 268
Groovy Question

data driven testing from excel using groovy scripting in soapui free version

Am getting the below error logs when am trying to do the parameterization using groovy with the follow code:

package org.codehaus.groovy.antlr.parser;
import jxl.*;
import org.codehaus.groovy.antlr.parser.GroovyRecognizer;

Workbook workbook = Workbook.getWorkbook(new File("D:\\SOAPUI\\ConversionRate.xls")
Sheet sheet1 = workbook.getSheet("DataDriven");
row = sheet1.getRow(); col = sheet1.getColumns(); "Row Count =" +row "Column Count =" +col
for(i=1;i<row;i++) {
for(j=0;;j<col;j++) {
def celsius = testRunner.tetCase.getStepByName("Properties")
cell var = sheet1.getCell(i,j) var.getContents()

Note: I have placed all the jars along with jxl in bin/ext folder.

startup failed: Script7.groovy: 1: unable to resolve class @ line 1, column
org.codehaus.groovy.syntax.SyntaxException: unable to resolve class @ line 1, column 1.
at org.codehaus.groovy.ast.ClassCodeVisitorSupport.addError(
at org.codehaus.groovy.control.ResolveVisitor.visitClass(
at org.codehaus.groovy.control.ResolveVisitor.startResolving(
at org.codehaus.groovy.control.CompilationUnit$
at org.codehaus.groovy.control.CompilationUnit.applyToSourceUnits(
at org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(
at org.codehaus.groovy.control.CompilationUnit.processPhaseOperations(
at org.codehaus.groovy.control.CompilationUnit.compile(
at groovy.lang.GroovyClassLoader.parseClass(
at groovy.lang.GroovyShell.parseClass(
at groovy.lang.GroovyShell.parse(GroovyShell.ja`enter code here`va:739)
at groovy.lang.GroovyShell.parse(
at groovy.lang.GroovyShell.parse(
at com.eviware.soapui.impl.wsdl.panels.teststeps.GroovyScriptStepDesktopPanel$RunAction$
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(
at java.util.concurrent.ThreadPoolExecutor$
1 error

Answer Source

Groovy testStep doesn't have an autocomplete feature so sometimes it's a bit pain to deal with class methods and other typos... this is why you probably can't make your code work. So let's go I'll try to enumerate the errors:

  • In SOAPUI Groovy testStep package its not necessary... furthermore this one is for sure not the correct one in your case: package org.codehaus.groovy.antlr.parser;
  • There are not necessaries import in your code:

    // groovy add* by default
    // this is not used in your code
    import org.codehaus.groovy.antlr.parser.GroovyRecognizer
  • There are also some typos; in the first line ) is missing to close getWorkbook(; you don't define any type for row and col variables; there is an extra ; in your loop for(j=0;;j<cols;j++).

  • To get the total number of rows and columns with jxl use Sheet.getColumns() and Sheet.getRows() instead.
  • jxl.Cellclass start with upper case (Java convention for class name is CamelCase)
  • Sheet.getCell(int column, int row) expect column position as a first argument, and row as second not the other way around.

So your code corrected could be:

import jxl.*

Workbook workbook = Workbook.getWorkbook(new File("D:/SOAPUI/ConversionRate.xls"))
Sheet sheet1 = workbook.getSheet("DataDriven")
def rows = sheet1.getRows()
def cols = sheet1.getColumns() "Row Count =" + rows "Column Count =" + cols 
for(i=1;i<rows;i++) { 
    for(j=0;j<cols;j++) { 
       Cell cell = sheet1.getCell(j,i) cell.getContents() 

Note that I don't test it but I suppose that once is corrected must works, go ahead an try it.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download