Selenium数据驱动的测试编号从excel读取为十进制

时间:2014-07-23 10:47:48

标签: java apache-poi automated-tests

在测试中,某些字段接受数字,并且已在excel中给出。但是当从excel读取数据时,它将读取为小数。例如,数字22被读为22.0。我用过apache.poi进行测试。如何避免小数。

public static void main(String[] args) throws InterruptedException {
    try{
        FileInputStream input = new FileInputStream("C:Users\\dinu\\Desktop\\RegDetails.xls");
        HSSFWorkbook wb = new HSSFWorkbook(input);
        HSSFSheet sheet = wb.getSheet("RegDetails");
        for(int count =1; count <= sheet.getLastRowNum(); count++){
            HSSFRow row = sheet.getRow(count);
            System.out.println("Running Test Case "+row.getCell(0).toString());
            runTest(row.getCell(1).toString(),row.getCell(2).toString(),row.getCell(3).toString(),
                    row.getCell(4).toString(),row.getCell(5).toString(),row.getCell(6).toString(),
                    row.getCell(7).toString(),row.getCell(8).toString());
        }input.close();
    }catch (IOException e){
        System.out.println("Test data not found.");
    }

1 个答案:

答案 0 :(得分:0)

使用它,它将起作用...

           for (int i = 0; i < sheet.getLastRowNum(); i++) {
            Row row = sheet.getRow(i + 1);
            for (int k = 0; k < sheet.getRow(0).getLastCellNum(); k++) {
                Cell cell = row.getCell(k);
                String value;
                try {
                    value = cell.getRichStringCellValue().toString();
                } catch (Exception e) {
                    value = ((XSSFCell) cell).getRawValue();
                }
                data[i][k] = value;
            }