I am getting the exception
ERROR:Exception happened: groovy.lang.GroovyRuntimeException: Could not find matching constructor for: jxl.write.Label(java.lang.Integer, java.lang.String, java.lang.String)
When I try to write the response value to excel using groovy. In this groovy script, I am trying to write the status(pass/fail) of soap request to an excel along with the request and response node values
Here is my code
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();
}
}
CodePudding user response:
If you read the error message carefully it tells you what's wrong:
Could not find matching constructor for: jxl.write.Label(java.lang.Integer, java.lang.String, java.lang.String)
You're passing (int, String, String)
, looks like it could be at label4
Label takes three parameters:
jxl.write.Label(int column, int row, java.lang.String content)
I haven't tested it, but you should be able to get it to work by converting the string row number to an int with parseInt(str)