Challenge - 5 Problems
Excel Data Reading Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
What is the output of this Apache POI code snippet reading Excel?
Given the following Java code snippet using Apache POI to read an Excel file, what will be printed to the console?
Selenium Java
FileInputStream fis = new FileInputStream("data.xlsx"); Workbook workbook = WorkbookFactory.create(fis); Sheet sheet = workbook.getSheetAt(0); Row row = sheet.getRow(1); Cell cell = row.getCell(2); System.out.println(cell.getStringCellValue()); workbook.close(); fis.close();
Attempts:
2 left
💡 Hint
Check the cell type and the row/column indices carefully.
✗ Incorrect
The code reads the first sheet, second row (index 1), third cell (index 2) and prints its string value. Assuming the Excel file has "TestValue" in that cell, it prints it. No exceptions occur if the file exists and cell is string type.
❓ assertion
intermediate1:30remaining
Which assertion correctly verifies the Excel cell value?
You read a cell value from Excel using Apache POI and want to assert it equals "Pass" in a Selenium Java test. Which assertion is correct?
Selenium Java
String actualValue = sheet.getRow(0).getCell(1).getStringCellValue();
Attempts:
2 left
💡 Hint
Use the correct assertion method for string equality in Java.
✗ Incorrect
assertEquals compares string contents correctly. Using == compares references and may fail. assertFalse and assertNull are incorrect here.
🔧 Debug
advanced2:30remaining
Why does this Apache POI code throw NullPointerException?
This code throws NullPointerException at runtime. What is the most likely cause?
Selenium Java
Workbook wb = WorkbookFactory.create(new FileInputStream("test.xlsx")); Sheet sh = wb.getSheetAt(0); Row r = sh.getRow(5); Cell c = r.getCell(3); String val = c.getStringCellValue(); System.out.println(val);
Attempts:
2 left
💡 Hint
Check which object is null before calling methods on it.
✗ Incorrect
If the row does not exist, getRow returns null. Calling getCell on null causes NullPointerException. Numeric cells cause different exceptions, not NPE.
❓ locator
advanced2:00remaining
Which locator is best to find the Excel file for reading in Selenium Java?
You want to load an Excel file named "data.xlsx" located in the "resources" folder inside your project root. Which code correctly locates the file for Apache POI reading?
Attempts:
2 left
💡 Hint
Use absolute path based on project root for reliable file access.
✗ Incorrect
Option A uses user.dir system property to get project root and appends relative path, ensuring correct file location regardless of working directory. Others may fail if relative path is incorrect.
❓ framework
expert3:00remaining
How to integrate Apache POI Excel reading in a Selenium TestNG framework for data-driven tests?
Which approach correctly integrates Apache POI to provide test data to a TestNG Selenium test method?
Attempts:
2 left
💡 Hint
TestNG supports data-driven tests via @DataProvider.
✗ Incorrect
Using @DataProvider to read Excel data with Apache POI and supply it to test methods is the standard and clean approach. Reading inside @Test or hardcoding data is not scalable. Selenium cannot read Excel UI.