Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Selenium IDE:从excel读取数据集_Excel_Selenium_Parameters_Ide - Fatal编程技术网

Selenium IDE:从excel读取数据集

Selenium IDE:从excel读取数据集,excel,selenium,parameters,ide,Excel,Selenium,Parameters,Ide,这实际上不是一个问题,而是一个解决方案建议:我找到了从excel读取数据集的解决方法。在这种情况下,不需要多个用户或数据变体,只需要读取参数来创建验证环境 好的,解决方案是将excel文件保存为html格式,然后让Selenium IDE从中读取参数。用户只需同意使用相同的文件名即可。1)您应该添加“ApachePOI”jar文件,以便通过java读取excel。 1) you should add "Apache POI" jar files in order to read your exc

这实际上不是一个问题,而是一个解决方案建议:我找到了从excel读取数据集的解决方法。在这种情况下,不需要多个用户或数据变体,只需要读取参数来创建验证环境

好的,解决方案是将excel文件保存为html格式,然后让Selenium IDE从中读取参数。用户只需同意使用相同的文件名即可。

1)您应该添加“ApachePOI”jar文件,以便通过java读取excel。
1) you should add "Apache POI" jar files in order to read your excel through java.


import java.io.FileInputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

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

public class ExcelReadExample {

    @SuppressWarnings({ "unchecked", "rawtypes" })
    public static void main(String[] args) throws Exception {



        String filename = "E:\\data.xls";



        List sheetData = new ArrayList();

        FileInputStream fis = null;
        try {

            fis = new FileInputStream(filename);

            XSSFWorkbook workbook = new XSSFWorkbook(fis);

            XSSFSheet sheet = workbook.getSheetAt(0);

            Iterator rows = sheet.rowIterator();
            while (rows.hasNext()) {
                XSSFRow row = (XSSFRow) rows.next();
                Iterator cells = row.cellIterator();

                List data = new ArrayList();
                while (cells.hasNext()) {
                    XSSFCell cell = (XSSFCell) cells.next();
                    data.add(cell);
                }

                sheetData.add(data);
            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (fis != null) {
                fis.close();
            }
        }

        showExelData(sheetData);
    }

    private static void showExelData(List sheetData) {


        int sum = 0;




        for (int i = 0; i < sheetData.size(); i++) {
            List<XSSFCell> list = (List) sheetData.get(i);
            for (int j = 0; j < list.size(); j++) {
                XSSFCell cell = (XSSFCell) list.get(j);


                if(cell.getCellType()==0)
                {
                    sum += cell.getNumericCellValue();

                }

            }
            System.out.println("");
            System.out.println("Sum Value is:" +sum);
        }
    }
}



Change the file path.
i hve mentioned my sheet name as "input" change it as per yours
Happy excelling :D
导入java.io.FileInputStream; 导入java.io.IOException; 导入java.util.ArrayList; 导入java.util.HashMap; 导入java.util.Iterator; 导入java.util.List; 导入java.util.Map; 导入org.apache.poi.xssf.usermodel.XSSFCell; 导入org.apache.poi.xssf.usermodel.XSSFRow; 导入org.apache.poi.xssf.usermodel.xssfheet; 导入org.apache.poi.xssf.usermodel.xssf工作簿; 公共类ExcelReadExample{ @SuppressWarnings({“unchecked”,“rawtypes”}) 公共静态void main(字符串[]args)引发异常{ 字符串filename=“E:\\data.xls”; List sheetData=new ArrayList(); FileInputStream fis=null; 试一试{ fis=新文件输入流(文件名); XSSF工作簿=新XSSF工作簿(fis); XSSFSheet sheet=workbook.getSheetAt(0); 迭代器行=sheet.rowIterator(); while(rows.hasNext()){ XSSFRow行=(XSSFRow)行。下一步(); 迭代器单元格=行。单元格迭代器(); 列表数据=新的ArrayList(); while(cells.hasNext()){ XSSFCell cell=(XSSFCell)cells.next(); 添加数据(单元格); } sheetData.add(数据); } }捕获(IOE异常){ e、 printStackTrace(); }最后{ 如果(fis!=null){ fis.close(); } } showExelData(sheetData); } 私有静态void showExelData(列表数据){ 整数和=0; 对于(int i=0;i