Error in for loop to fetch data from excel in selenium

0 votes

I’m generating the extent report and I’m fetching the data from excel file. Condition is if the string fetched from excel is "Found" then my test should pass otherwise fail, but in this code it only fetches the data from the first row in the excel.

 

@Test

    public void passTest() throws IOException {

        File src = new File("F:\\drive f\\DemoReport.xlsx");

        FileInputStream fis = new FileInputStream(src);

        XSSFWorkbook wb = new XSSFWorkbook(fis);

        XSSFSheet sheet1 = wb.getSheetAt(0);

 

        int rowcount = sheet1.getLastRowNum();

        for(int i=1;i<=rowcount;i++) {

 

            String str = sheet1.getRow(i).getCell(2).getStringCellValue();

            String str1 = sheet1.getRow(i).getCell(1).getStringCellValue();

            double j = sheet1.getRow(i).getCell(3).getNumericCellValue();

            fis.close();

 

            String exp1 = "Found";

            String exp2 = "Not Found";

            if(str.equals(exp1)) {

                logger=extent.createTest(str1);

                Assert.assertTrue(true);

                logger.log(Status.PASS, MarkupHelper.createLabel(str1 + " found at index " + j, ExtentColor.GREEN));

            }

            else if(str.equals(exp2)) {

                logger=extent.createTest(str1);

                Assert.assertTrue(true);

                logger.log(Status.FAIL, MarkupHelper.createLabel(str1 + "is not found", ExtentColor.RED));

            }

        }

    }
Jun 20, 2018 in Selenium by Martin
• 4,210 points
128 views

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
0 votes

You are closing theFileInputStream inside the for-loop. Use fis.close(); after for-loop ends.

answered Jun 20, 2018 by Samarpit
• 5,130 points

Related Questions In Selenium

0 votes
1 answer

Reading data from Excel in my Selenium test

Log4j problems are usually thrown because of ...READ MORE

answered Apr 6, 2018 in Selenium by nsv999
• 5,030 points
1,740 views
0 votes
0 answers
0 votes
1 answer
0 votes
1 answer

How to choose from a drop-down in Selenium 2?

You can probably use the 'Select' class ...READ MORE

answered Apr 24, 2018 in Selenium by king_kenny
• 3,590 points
27 views
0 votes
1 answer

Finding WebDriver element with Class Name in java

The better way to handle this element ...READ MORE

answered Apr 10, 2018 in Selenium by nsv999
• 5,030 points
51 views
0 votes
1 answer
0 votes
1 answer

Geo-location microphone camera pop up

To Allow or Block the notification, access using Selenium and you have to ...READ MORE

answered May 11, 2018 in Selenium by Samarpit
• 5,130 points
413 views
0 votes
1 answer

How to use such xpath to find web elements

It's much simpler to use: #MyDiv123 > div.super or ...READ MORE

answered Jun 14, 2018 in Selenium by Samarpit
• 5,130 points
40 views
0 votes
1 answer

How to eliminate this error”Cannot instantiate the type Select in selenium webdriver”

Try below code. Select sc = new Select(driver.findElement(By.xpath("your ...READ MORE

answered May 18, 2018 in Selenium by Samarpit
• 5,130 points
989 views
0 votes
1 answer

Read data from excel sheet in python

Try to use xrld. A python module used ...READ MORE

answered Jun 28, 2018 in Selenium by Samarpit
• 5,130 points
309 views

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.