1

It was working for me. I have closed Eclipse and executed the same runner(BDD, with Maven Project). I am getting the error:

java.lang.NoSuchMethodError: 'byte[] org.apache.commons.io.IOUtils.byteArray(int)' at org.apache.commons.io.output.AbstractByteArrayOutputStream.needNewBuffer(AbstractByteArrayOutputStream.java:104) at org.apache.commons.io.output.UnsynchronizedByteArrayOutputStream.(UnsynchronizedByteArrayOutputStream.java:51) at org.apache.poi.util.IOUtils.peekFirstNBytes(IOUtils.java:139) at org.apache.poi.poifs.filesystem.FileMagic.valueOf(FileMagic.java:209) at org.apache.poi.openxml4j.opc.internal.ZipHelper.verifyZipHeader(ZipHelper.java:143) at org.apache.poi.openxml4j.opc.internal.ZipHelper.openZipStream(ZipHelper.java:175) at org.apache.poi.openxml4j.opc.ZipPackage.(ZipPackage.java:130) at org.apache.poi.openxml4j.opc.OPCPackage.open(OPCPackage.java:312) at org.apache.poi.ooxml.util.PackageHelper.open(PackageHelper.java:59) at org.apache.poi.xssf.usermodel.XSSFWorkbook.(XSSFWorkbook.java:289) at org.apache.poi.xssf.usermodel.XSSFWorkbook.(XSSFWorkbook.java:285) at StepDefinition.Steps.when_user_enters_filename(Steps.java:80) at ✽.a user enters "C:\Sejars\TestData.xlsx" and "Sheet1"(file:///C:/Users/Ashok%20Kumar/eclipse-workspace/CucumberWithSelenium/Features/MyTest.feature:20)

Infact it was working for me. But all of sudden it has started throwing errors. I have referred the previous posting suggested during posting this. One of the suggestions is to include ">poi-ooxml". But my POM is already having the same. I have changed the version of commons-io version. But still no use. Same error. Note that no error while building the code and build is successful at CMD prompt. But it's throwing at runtime is surpring me. I am using Eclipse and my JDK version is 17.0.2 and Maven version is: 3.8.5 Here I am listing my POM:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>CucumberWithSelenium</groupId>
  <artifactId>CucumberWithSelenium</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <build>
    <sourceDirectory>src</sourceDirectory>
    <plugins>
      <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.8.1</version>
        <configuration>
          <release>17</release>
        </configuration>
      </plugin>
    </plugins>
  </build>
<dependencies>

        <dependency>
            <groupId>io.cucumber</groupId>
            <artifactId>cucumber-java</artifactId>
            <version>7.2.3</version>
        </dependency>

        <dependency>
            <groupId>io.cucumber</groupId>
            <artifactId>cucumber-junit</artifactId>
            <version>7.2.3</version>
        </dependency>

        <dependency>
            <groupId>io.cucumber</groupId>
            <artifactId>cucumber-jvm-deps</artifactId>
            <version>1.0.6</version>
        </dependency>

        <dependency>
            <groupId>net.masterthought</groupId>
            <artifactId>cucumber-reporting</artifactId>
            <version>1.0.0</version>
        </dependency>

        <dependency>
            <groupId>io.cucumber</groupId>
            <artifactId>gherkin</artifactId>
            <version>22.0.0</version>
        </dependency>

        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.13.2</version>
        </dependency>


        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>4.1.2</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/info.cukes/cucumber-picocontainer -->
        <dependency>
            <groupId>io.cucumber</groupId>
            <artifactId>cucumber-picocontainer</artifactId>
            <version>7.2.3</version>
        </dependency>
<!-- https://mvnrepository.com/artifact/org.apache.poi/poi-ooxml -->
        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi-ooxml</artifactId>
            <version>5.2.2</version>
        </dependency>
<!-- https://mvnrepository.com/artifact/org.apache.commons/commons-lang3 -->
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-lang3</artifactId>
            <version>3.12.0</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/commons-io/commons-io -->
        <dependency>
            <groupId>commons-io</groupId>
            <artifactId>commons-io</artifactId>
            <version>2.10.0</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-log4j2 -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-log4j2</artifactId>
            <version>2.6.6</version>
        </dependency>


    </dependencies>
</project

1 Answers1

0

I did test some more on this problem and did debug the code. My guess is that there is a mismatch of versions of some JAR files. I did degrade the versions of Junit and commons-io. But still I am facing the same error. I have applied toggle breakpoint and found the error is at:

XSSFWorkbook wb = new XSSFWorkbook(fis);

Here is full code of my step file. For debugging purpose I am printing to know which line is throwing error. Requesting somebody to guide me:

@When("^a user enters \"(.*)\" and \"(.*)\"$")
public void when_user_enters_filename(String filename, String sheetname) throws Throwable{
    System.out.println("This is from RegressionTest: " + filename + " " + sheetname);
    String[][] data = null;
    try {
    FileInputStream fis = new FileInputStream(filename);
    //InputStream fis = new FileInputStream(filename);
    byte[] bytes = IOUtils.toByteArray(fis);

    System.out.println("Byte array size: " + bytes.length);
    try (**XSSFWorkbook wb = new XSSFWorkbook(fis)**) {
         System.out.println("Byte array size2: " + bytes.length);
        XSSFSheet sh = wb.getSheet(sheetname);
         System.out.println("Byte array size3: " + bytes.length);
        XSSFRow row = sh.getRow(0);
        int noOfRows = sh.getPhysicalNumberOfRows();
        int noOfCols = row.getLastCellNum();
        System.out.println("No of rows data = "+ noOfRows + " No of cols data = " + noOfCols);
        Cell cell;
        data = new String[noOfRows-1][noOfCols];
  for(int i =1; i<noOfRows;i++){
             for(int j=0;j<noOfCols;j++){
                   row = sh.getRow(i);
                   cell= row.getCell(j);
                   data[i-1][j] = cell.getStringCellValue();
                   System.out.println("row and col = " + i +" , " + j);
                   System.out.println("This is reading excel data" + cell.getStringCellValue());
               }
        }
    }
    
    fis.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
}