简体   繁体   English

硒数据驱动测试-从Excel读取为十进制数

[英]Selenium Data driven test- number read as decimal from excel

In the test some fields accepts numbers and it has been given in the excel. 在测试中,某些字段接受数字,并且已在excel中给出。 But when the data is read from the excel, it reads as decimals. 但是,当从excel读取数据时,它将读取为小数。 for example number 22 is read as 22.0. 例如,数字22读为22.0。 I have used apache.poi for the test. 我已经使用apache.poi进行了测试。 How to avoid decimal. 如何避免小数。

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.");
    }

Use this,it will work... 使用它,它将起作用...

           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;
            }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM