Reading data from Excel in selenium getting "Error occurred during initialization of boot layer":java.lang.module.ResolutionException:

huangapple 未分类评论62阅读模式
英文:

Reading data from Excel in selenium getting "Error occurred during initialization of boot layer":java.lang.module.ResolutionException:

问题

Code:

package Selenium;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;

import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellType;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.util.NumberToTextConverter;

public class excelReader {

// 通过扫描整个第一行来识别测试用例列
// 一旦识别出列,然后扫描整个测试用例列以识别购买测试用例行
// 在获取购买测试用例行之后,提取该行的所有数据并输入测试中

public static ArrayList<String> getData(String testcaseName) throws IOException {
    // fileInputStream 参数
    ArrayList<String> a = new ArrayList<String>();

    FileInputStream fis = new FileInputStream("C://Users//Sivaranjani Gopal//Desktop//siva.xlsx");
    XSSFWorkbook workbook = new XSSFWorkbook(fis);

    int sheets = workbook.getNumberOfSheets();

    for (int i = 0; i < sheets; i++) {
        if (workbook.getSheetName(i).equalsIgnoreCase("testdata")) {
            XSSFSheet sheet = workbook.getSheetAt(i);
            // 通过扫描整个第一行来识别测试用例列
            Iterator<Row> rows = sheet.iterator();
            Row firstrow = rows.next();

            Iterator<Cell> ce = firstrow.cellIterator(); // 行是单元格的集合
            int k = 0;
            int column = 0;

            while (ce.hasNext()) {
                Cell value = ce.next();

                if (value.getStringCellValue().equalsIgnoreCase("TestCases")) {
                    column = k;
                }

                k++;
            }

            System.out.println(column);

            // 一旦识别出列,然后扫描整个测试用例列以识别购买测试用例行
            while (rows.hasNext()) {
                Row r = rows.next();

                if (r.getCell(column).getStringCellValue().equalsIgnoreCase(testcaseName)) {
                    // 在获取购买测试用例行之后,提取该行的所有数据并输入测试中
                    Iterator<Cell> cv = r.cellIterator();

                    while (cv.hasNext()) {
                        Cell c = cv.next();

                        if (c.getCellTypeEnum() == CellType.STRING) {
                            a.add(c.getStringCellValue());
                        } else {
                            a.add(NumberToTextConverter.toText(c.getNumericCellValue()));
                        }
                    }
                }
            }
        }
    }

    return a;
}

public static void main(String[] args) throws IOException {
    // TODO Auto-generated method stub
    getData("siva");
}

Could someone help on the error?

I am getting the below exception when I run the code:

> Error occurred during initialization of boot layer
> java.lang.module.ResolutionException: Modules jaxb.impl and jaxb.core export package com.sun.xml.bind.v2.model.annotation to module poi

Need help on the above exception.
英文:

Code :

package Selenium;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;

import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellType;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.util.NumberToTextConverter;

public class excelReader {

//Identify Testcases column by scanning the entire 1st row
//once column is identified then scan entire testcase column to identify purchase testcase row
//after you grab purchase testcase row = pull all the data of that row and feed into test

public static ArrayList&lt;String&gt; getData(String testcaseName) throws IOException
{
    // fileInputStream argument
    ArrayList&lt;String&gt; a = new ArrayList&lt;String&gt;();

    FileInputStream fis = new FileInputStream(&quot;C://Users//Sivaranjani Gopal//Desktop//siva.xlsx&quot;);
    XSSFWorkbook workbook=new XSSFWorkbook(fis);

    int sheets = workbook.getNumberOfSheets();

    for (int i = 0; i &lt; sheets; i++)
    {
        if (workbook.getSheetName(i).equalsIgnoreCase(&quot;testdata&quot;))
        {
            XSSFSheet sheet = workbook.getSheetAt(i);
            // Identify Testcases column by scanning the entire 1st row
            Iterator&lt;Row&gt; rows = sheet.iterator();
            Row firstrow = rows.next();

            Iterator&lt;Cell&gt; ce = firstrow.cellIterator();//row is collection of cells
            int k = 0;
            int column = 0;

            while (ce.hasNext())
            {
                Cell value = ce.next();
 
                if (value.getStringCellValue().equalsIgnoreCase(&quot;TestCases&quot;))
                {
                    column = k;
                }

                k++;
            }

            System.out.println(column);
 
            // once column is identified then scan entire testcase column to identify purchase testcase row
            while (rows.hasNext())
            {
                Row r = rows.next();

                if (r.getCell(column).getStringCellValue().equalsIgnoreCase(testcaseName))
                {
                    // after you grab purchase testcase row = pull all the data of that row and feed into test
                    Iterator&lt;Cell&gt; cv = r.cellIterator();

                    while (cv.hasNext())
                    {
                        Cell c = cv.next();

                        if (c.getCellTypeEnum() == CellType.STRING)
                        {
                            a.add(c.getStringCellValue());
                        }
                        else
                        {
                            a.add(NumberToTextConverter.toText(c.getNumericCellValue()));
                        }
                    }
                }
            }
        }
    }

    return a;
}

public static void main(String[] args) throws IOException 
{
    // TODO Auto-generated method stub
	getData(&quot;siva&quot;);
}

Could some one help on the error?

I am getting the below exception when I run the code:

> Error occurred during initialization of boot layer
> java.lang.module.ResolutionException: Modules jaxb.impl and jaxb.core export package com.sun.xml.bind.v2.model.annotation to module poi

Need help on the above exception.

huangapple
  • 本文由 发表于 2020年4月8日 16:46:20
  • 转载请务必保留本文链接:https://java.coder-hub.com/61096707.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定