在 Groovy 脚本中创建类 [英] Creating Classes in Groovy Script
问题描述
我正在尝试使用 groovy 脚本步骤编写类并在soap UI 中我需要的任何地方执行.
但它显示错误为:
I am trying to write classes and execute wherever I need in soap UI using groovy script step.
But it is showing error as :
"org.codehaus.groovy.runtime.metaclass.MissingMethodExceptionNoStack:没有方法签名: excel.main() 适用于参数类型:([Ljava.lang.String;) 值:[[]] 可能的解决方案:wait(),wait(long), find(), any(), wait(long, int), find(groovy.lang.Closure)
"org.codehaus.groovy.runtime.metaclass.MissingMethodExceptionNoStack: No signature of method: excel.main() is applicable for argument types: ([Ljava.lang.String;) values: [[]] Possible solutions: wait(), wait(long), find(), any(), wait(long, int), find(groovy.lang.Closure)
import groovy.json.JsonSlurper
import java.io.*;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.ss.usermodel.*;
import java.util.Iterator;
class excel {
static void ReadWriteExcel(String a,int b)
{
def projectPath = new
com.eviware.soapui.support.GroovyUtils(context).projectPath
//gets the path of the project root
FileInputStream fIpStream= new
FileInputStream(projectPath+"\\Bat_File_Data.xls")
HSSFWorkbook wb = new HSSFWorkbook(fIpStream);
HSSFSheet worksheet = wb.getSheetAt(0);
int noOfRows = worksheet.getLastRowNum();
int noOfColumns = worksheet.getRow(0).getLastCellNum();
for (int i=1;i<2;i++)
{
//def res = wb.getSheetAt(0).getRow(1).getCell(0);
def res = wb.getSheetAt(0).getRow(i).getCell(1);
//log.info res
Row row = worksheet.createRow(i);
Cell cell = row.createCell(2);
Cell cell1 = row.createCell(3);
cell.setCellValue(a);
cell1.setCellValue(b);
}
fIpStream.close(); //Close the InputStream
FileOutputStream output_file =new FileOutputStream(new
File(projectPath+"\\Bat_File_Data.xls"));
wb.write(output_file);
output_file.close();
}
}
class Groovy
{
static void main(String[] args)
{
ReadWriteExcel("Pass",2234);
}
}
推荐答案
在 groovy 脚本中,您可以像这样声明和访问它的静态方法:
in groovy script you can declare and access static methods of it like this:
class A{
static void greet(String name){
println "hello $name!"
}
}
//code without class declaration will be executed as part of script.run() method
A.greet("world")
这篇关于在 Groovy 脚本中创建类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!