找不到匹配的构造函数:jxl.write.Label(java.lang.Integer, java.lang.String, java.lang.String)
Could not find matching constructor for: jxl.write.Label(java.lang.Integer, java.lang.String, java.lang.String)
我遇到异常
错误:发生异常:groovy.lang.GroovyRuntimeException:找不到匹配的构造函数:jxl.write.Label(java.lang.Integer, java.lang.String, java.lang.String)
当我尝试使用 groovy 将响应值写入 excel 时。
在这个 groovy 脚本中,我尝试将 soap 请求的状态 (pass/fail) 连同请求和响应节点值
一起写入 excel
这是我的代码
import com.eviware.soapui.support.XmlHolder
import com.eviware.soapui.impl.wsdl.testcase.WsdlTestRunContext
import jxl.*
import jxl.write.*
import jxl.write.Label
def TestCase = context.testCase
PropertiesTestStep = TestCase.getTestStepByName("Properties")
Stop = PropertiesTestStep.getPropertyValue("End").toString()
if(Stop!="True"){
def response = testRunner.testCase.getTestStepByName('GetSectors').getPropertyValue("response")
def samplexmlreq=new XmlHolder(response)
def count = PropertiesTestStep.getPropertyValue("Counter")
def result
def row = PropertiesTestStep.getPropertyValue("row")
def column = PropertiesTestStep.getPropertyValue("column")
def flag=0
WritableWorkbook wb
WritableSheet sheet
try
{
def token = samplexmlreq.getNodeValue("/*:Envelope/*:Body/tRisePtz:GetSectorsResponse/tRisePtz:Sectors["+count+"]/tRisePtz:SectorToken")
def name = samplexmlreq.getNodeValue("/*:Envelope/*:Body/tRisePtz:GetSectorsResponse/tRisePtz:Sectors["+count+"]/tRisePtz:SectorName")
def leftLimit = samplexmlreq.getNodeValue("/*:Envelope/*:Body/tRisePtz:GetSectorsResponse/tRisePtz:Sectors["+count+"]/tRisePtz:LeftLimit")
def rightLimit = samplexmlreq.getNodeValue("/*:Envelope/*:Body/tRisePtz:GetSectorsResponse/tRisePtz:Sectors["+count+"]/tRisePtz:RightLimit")
def TokenFromProperies = PropertiesTestStep.getPropertyValue("SectorToken")
def NameFromProperies = PropertiesTestStep.getPropertyValue("SectorName")
def LeftLimitFromProperies = PropertiesTestStep.getPropertyValue("LeftLimit")
def RightLimitFromProperies = PropertiesTestStep.getPropertyValue("RightLimit")
if(name == NameFromProperies && leftLimit == LeftLimitFromProperies &&
rightLimit == RightLimitFromProperies )
{
result = "Passed"
}
else
{
result = "Failed"
}
def projectPath = new com.eviware.soapui.support.GroovyUtils(context).projectPath
def folderPath = projectPath + "/SoapUIResults/SectorOSDActions/";
def resultFolder = new File(folderPath);
if(!resultFolder.exists())
{
resultFolder.mkdirs();
}
def file = new File(resultFolder,"TestSuite_Report.xls").exists()
//Creating workbook if not exists
if(!file){
wb = Workbook.createWorkbook(new File(resultFolder ,"TestSuite_Report.xls"))
}
else
{
wb = Workbook.getWorkbook(new File(resultFolder,"TestSuite_Report.xls"))
}
//Creating sheet if not exist
if (wb.getNumberOfSheets() != 0) {
for (int i = 0; i < wb.getNumberOfSheets(); i++) {
if (wb.getSheetName(i).equals("GoToSector")) {
sheet = wb.getSheet("GoToSector");
flag=1
break;
}
}
}
if(flag == 0){
sheet = wb.createSheet("GoToSector",0);
Label label = new Label(0, 0, "Type"); //column=0=A,row=0=1
sheet.addCell(label);
Label label1 = new Label(1, 0, "SectorName");
sheet.addCell(label1);
Label label2 = new Label(2, 0, "LeftLimit");
sheet.addCell(label2);
Label label3 = new Label(3, 0, "RightLimit");
sheet.addCell(label3);
}
Label label4 = new Label(0,row,"Request")
sheet.addCell(label4);
Label label5 = new Label(column+1,row,NameFromProperies)
sheet.addCell(label5);
Label label6 = new Label(column+2,row,LeftLimitFromProperies)
sheet.addCell(label6);
Label label7 = new Label(column+3,row,RightLimitFromProperies)
sheet.addCell(label7);
Label label8 = new Label(0,row,"Response")
sheet.addCell(label8);
Label label9 = new Label(column,row+1,name)
sheet.addCell(label9);
Label label10 = new Label(column,row+2,leftLimit)
sheet.addCell(label10);
Label label11 = new Label(column,row+3,rightLimit)
sheet.addCell(label11);
Label label12 = new Label(0,row,"Status")
sheet.addCell(label11);
Label label13 = new Label(column,row,result)
sheet.addCell(label11);
wb.write() //Getting error if I comment this
wb.close() //getting error if I comment this
PropertiesTestStep.setPropertyValue("row",row+1)
PropertiesTestStep.setPropertyValue("column",column+1)
// WritableSheet sheetToEdit = wb1.getSheet("Sheet1");
// WritableCell cell;
}
catch(exc)
{
log.error("Exception happened: " + exc.toString());
}
finally{
wb.write();
wb.close();
}
}
如果您仔细阅读错误消息,它会告诉您出了什么问题:
Could not find matching constructor for: jxl.write.Label(java.lang.Integer, java.lang.String, java.lang.String)
您即将超过 (int, String, String)
,看起来它可能在 label4
Label 接受三个参数:
jxl.write.Label(int column, int row, java.lang.String content)
我还没有测试过,但是你应该能够通过使用 parseInt(str)
将字符串行号转换为 int 来让它工作
我遇到异常
错误:发生异常:groovy.lang.GroovyRuntimeException:找不到匹配的构造函数:jxl.write.Label(java.lang.Integer, java.lang.String, java.lang.String)
当我尝试使用 groovy 将响应值写入 excel 时。 在这个 groovy 脚本中,我尝试将 soap 请求的状态 (pass/fail) 连同请求和响应节点值
一起写入 excel这是我的代码
import com.eviware.soapui.support.XmlHolder
import com.eviware.soapui.impl.wsdl.testcase.WsdlTestRunContext
import jxl.*
import jxl.write.*
import jxl.write.Label
def TestCase = context.testCase
PropertiesTestStep = TestCase.getTestStepByName("Properties")
Stop = PropertiesTestStep.getPropertyValue("End").toString()
if(Stop!="True"){
def response = testRunner.testCase.getTestStepByName('GetSectors').getPropertyValue("response")
def samplexmlreq=new XmlHolder(response)
def count = PropertiesTestStep.getPropertyValue("Counter")
def result
def row = PropertiesTestStep.getPropertyValue("row")
def column = PropertiesTestStep.getPropertyValue("column")
def flag=0
WritableWorkbook wb
WritableSheet sheet
try
{
def token = samplexmlreq.getNodeValue("/*:Envelope/*:Body/tRisePtz:GetSectorsResponse/tRisePtz:Sectors["+count+"]/tRisePtz:SectorToken")
def name = samplexmlreq.getNodeValue("/*:Envelope/*:Body/tRisePtz:GetSectorsResponse/tRisePtz:Sectors["+count+"]/tRisePtz:SectorName")
def leftLimit = samplexmlreq.getNodeValue("/*:Envelope/*:Body/tRisePtz:GetSectorsResponse/tRisePtz:Sectors["+count+"]/tRisePtz:LeftLimit")
def rightLimit = samplexmlreq.getNodeValue("/*:Envelope/*:Body/tRisePtz:GetSectorsResponse/tRisePtz:Sectors["+count+"]/tRisePtz:RightLimit")
def TokenFromProperies = PropertiesTestStep.getPropertyValue("SectorToken")
def NameFromProperies = PropertiesTestStep.getPropertyValue("SectorName")
def LeftLimitFromProperies = PropertiesTestStep.getPropertyValue("LeftLimit")
def RightLimitFromProperies = PropertiesTestStep.getPropertyValue("RightLimit")
if(name == NameFromProperies && leftLimit == LeftLimitFromProperies &&
rightLimit == RightLimitFromProperies )
{
result = "Passed"
}
else
{
result = "Failed"
}
def projectPath = new com.eviware.soapui.support.GroovyUtils(context).projectPath
def folderPath = projectPath + "/SoapUIResults/SectorOSDActions/";
def resultFolder = new File(folderPath);
if(!resultFolder.exists())
{
resultFolder.mkdirs();
}
def file = new File(resultFolder,"TestSuite_Report.xls").exists()
//Creating workbook if not exists
if(!file){
wb = Workbook.createWorkbook(new File(resultFolder ,"TestSuite_Report.xls"))
}
else
{
wb = Workbook.getWorkbook(new File(resultFolder,"TestSuite_Report.xls"))
}
//Creating sheet if not exist
if (wb.getNumberOfSheets() != 0) {
for (int i = 0; i < wb.getNumberOfSheets(); i++) {
if (wb.getSheetName(i).equals("GoToSector")) {
sheet = wb.getSheet("GoToSector");
flag=1
break;
}
}
}
if(flag == 0){
sheet = wb.createSheet("GoToSector",0);
Label label = new Label(0, 0, "Type"); //column=0=A,row=0=1
sheet.addCell(label);
Label label1 = new Label(1, 0, "SectorName");
sheet.addCell(label1);
Label label2 = new Label(2, 0, "LeftLimit");
sheet.addCell(label2);
Label label3 = new Label(3, 0, "RightLimit");
sheet.addCell(label3);
}
Label label4 = new Label(0,row,"Request")
sheet.addCell(label4);
Label label5 = new Label(column+1,row,NameFromProperies)
sheet.addCell(label5);
Label label6 = new Label(column+2,row,LeftLimitFromProperies)
sheet.addCell(label6);
Label label7 = new Label(column+3,row,RightLimitFromProperies)
sheet.addCell(label7);
Label label8 = new Label(0,row,"Response")
sheet.addCell(label8);
Label label9 = new Label(column,row+1,name)
sheet.addCell(label9);
Label label10 = new Label(column,row+2,leftLimit)
sheet.addCell(label10);
Label label11 = new Label(column,row+3,rightLimit)
sheet.addCell(label11);
Label label12 = new Label(0,row,"Status")
sheet.addCell(label11);
Label label13 = new Label(column,row,result)
sheet.addCell(label11);
wb.write() //Getting error if I comment this
wb.close() //getting error if I comment this
PropertiesTestStep.setPropertyValue("row",row+1)
PropertiesTestStep.setPropertyValue("column",column+1)
// WritableSheet sheetToEdit = wb1.getSheet("Sheet1");
// WritableCell cell;
}
catch(exc)
{
log.error("Exception happened: " + exc.toString());
}
finally{
wb.write();
wb.close();
}
}
如果您仔细阅读错误消息,它会告诉您出了什么问题:
Could not find matching constructor for: jxl.write.Label(java.lang.Integer, java.lang.String, java.lang.String)
您即将超过 (int, String, String)
,看起来它可能在 label4
Label 接受三个参数:
jxl.write.Label(int column, int row, java.lang.String content)
我还没有测试过,但是你应该能够通过使用 parseInt(str)