Challenge - 5 Problems
CSV Data Reading Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Reading CSV file with BufferedReader
What will be the output of this Selenium Java code snippet that reads a CSV file line by line and prints each line?
Selenium Java
import java.io.*; public class CsvReader { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new FileReader("data.csv")); String line; while ((line = br.readLine()) != null) { System.out.println(line); } br.close(); } } // Assume data.csv content: // name,age,city // Alice,30,New York // Bob,25,Los Angeles
Attempts:
2 left
💡 Hint
Look carefully at how BufferedReader reads lines and prints them exactly as in the file.
✗ Incorrect
BufferedReader reads each line as a string and prints it exactly. Since the CSV uses commas, the output lines contain commas.
❓ assertion
intermediate2:00remaining
Validating CSV data read into a list
Given this code snippet that reads CSV data into a List in Selenium Java, which assertion correctly verifies the second row's first column is 'Alice'?
Selenium Java
import java.io.*; import java.util.*; public class CsvData { public static List<String[]> readCsv(String filePath) throws IOException { List<String[]> data = new ArrayList<>(); BufferedReader br = new BufferedReader(new FileReader(filePath)); String line; while ((line = br.readLine()) != null) { data.add(line.split(",")); } br.close(); return data; } }
Attempts:
2 left
💡 Hint
Remember that list index 0 is the header row.
✗ Incorrect
The first row (index 0) is the header, so the second row (index 1) contains 'Alice' in the first column (index 0).
🔧 Debug
advanced2:00remaining
Fixing CSV file path error in Selenium Java test
This Selenium Java code throws a FileNotFoundException when trying to read 'data.csv'. What is the most likely cause?
Selenium Java
BufferedReader br = new BufferedReader(new FileReader("data.csv"));
String line = br.readLine();
br.close();Attempts:
2 left
💡 Hint
Check where the program looks for the file relative to the running location.
✗ Incorrect
FileNotFoundException usually means the file path is incorrect or the file is missing in the expected directory.
❓ framework
advanced2:00remaining
Best practice for CSV data-driven tests in Selenium Java
Which approach is best to integrate CSV data reading into Selenium Java tests for multiple test cases?
Attempts:
2 left
💡 Hint
Think about reusability and separation of test data from test logic.
✗ Incorrect
TestNG DataProvider allows clean, reusable data-driven tests by reading CSV once and feeding data to multiple tests.
🧠 Conceptual
expert3:00remaining
Handling special characters in CSV data reading
When reading CSV files with Selenium Java tests, which issue can arise if the CSV contains commas inside quoted fields, and how to handle it?
Attempts:
2 left
💡 Hint
Think about how simple split by comma treats commas inside quotes.
✗ Incorrect
Simple split by comma fails on quoted fields containing commas. Libraries like OpenCSV parse CSV correctly respecting quotes.