【问题标题】:Could not find matching constructor for: jxl.write.Label(java.lang.Integer, java.lang.String, java.lang.String)找不到匹配的构造函数:jxl.write.Label(java.lang.Integer, java.lang.String, java.lang.String)
【发布时间】:2022-01-09 15:21:51
【问题描述】:

我遇到了异常

错误:发生异常:groovy.lang.GroovyRuntimeException:找不到匹配的构造函数:jxl.write.Label(java.lang.Integer, java.lang.String, java.lang.String)

当我尝试使用 groovy 将响应值写入 excel 时。 在这个 groovy 脚本中,我试图将soap请求的状态(通过/失败)连同请求和响应节点值一起写入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();
}
}

【问题讨论】:

  • 向我们展示您的代码,以便我们为您提供帮助。
  • @ou_ryperd 我已经更新了问题并添加了代码。请尝试解决它
  • 还有一个查询。我们可以使用 groovy 为标题设置字体类型为粗体,为结果值设置字体颜色为红色/绿色吗
  • 是的,你可以。您必须查看API docs 并查看您需要什么。

标签: java api groovy automation soapui


【解决方案1】:

如果您仔细阅读错误消息,它会告诉您问题所在:

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来让它工作

【讨论】:

    猜你喜欢
    • 2016-01-26
    • 2016-06-17
    • 1970-01-01
    • 2016-08-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多