Search code examples
selenium-webdriverapache-poitestng-dataprovider

Getting "java.lang.NoClassDefFoundError" for Testng Dataprovider with Excel


I am not able to get past the error "java.lang.NoClassDefFoundError"

Tried: 1- Cleaning the project 2- Updating testng xml 3- Verified the package/class structure

Nothing seems to work:

Note: I am not using Maven and all jar files are latest (Testng, Apache, Selenium)

Test Class code :

@DataProvider(name ="calldata")
public Object[][] getData() {

    ExcelUtility util = new ExcelUtility("excel path");

    int rows = util.getRowCount(0);

    Object data [][] = new Object[rows] [6];

    for(int i=1; i<rows; i++)
    {
        data[i][0]=util.getData(0, i, 0);
        data[i][1]=util.getData(0, i, 1);
        data[i][1]=util.getData(0, i, 2);
        data[i][1]=util.getData(0, i, 3);
        data[i][1]=util.getData(0, i, 4);
        data[i][1]=util.getData(0, i, 5);
    }

    return data;
}

@Test(dataProvider ="calldata")
 public void AddaDependent(String url, String client, String eliggrp, String empnumber, String firstname, String SSN) 
    {

Excel Utility code:

package AllExcel;

import java.io.File; import java.io.FileInputStream;

import org.apache.poi.xssf.usermodel.XSSFSheet; import org.apache.poi.xssf.usermodel.XSSFWorkbook;

public class ExcelUtility {

XSSFWorkbook wb;
XSSFSheet sheet1;

public ExcelUtility(String excelPath)
{
    try
    {
        File src = new File(excelPath);

        FileInputStream fis= new FileInputStream(src);
        wb = new XSSFWorkbook(fis);

    }
    catch (Exception e) {
        System.out.println(e.getMessage());

    }
}

public String getData(int sheetNumber, int row, int column)
{
    sheet1 = wb.getSheetAt(0);

    String data = sheet1.getRow(row).getCell(column).getStringCellValue();

    return data;
}

public int getRowCount(int sheetIndex)
{
    int row = wb.getSheetAt(sheetIndex).getLastRowNum();

    row = row+1;

    return row;
}

}

Error:

[RemoteTestNG] detected TestNG version 6.14.3 [Utils] [ERROR] [Error] java.lang.NoClassDefFoundError: org/apache/commons/compress/archivers/zip/ZipFile at org.apache.poi.openxml4j.opc.OPCPackage.open(OPCPackage.java:298) at org.apache.poi.ooxml.util.PackageHelper.open(PackageHelper.java:37) at org.apache.poi.xssf.usermodel.XSSFWorkbook.<init>(XSSFWorkbook.java:307) at AllExcel.ExcelUtility.<init>(ExcelUtility.java:22) at AutFramework.AddDependent.getData(AddDependent.java:36) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source)


Solution

  • Basically as per Axel's link, I copied "common compress jar" and the mentioned error went away, now I am getting another error and that needs to be handled in another question. closing this one for now