0
0
Selenium Javatesting~20 mins

CSV data reading in Selenium Java - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
CSV Data Reading Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2: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
A
name,age,city
Alice,30,New York
Bob,25,Los Angeles
B
name;age;city
Alice;30;New York
Bob;25;Los Angeles
C
name|age|city
Alice|30|New York
Bob|25|Los Angeles
DSyntaxError at line 4
Attempts:
2 left
💡 Hint
Look carefully at how BufferedReader reads lines and prints them exactly as in the file.
assertion
intermediate
2: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;
    }
}
AassertFalse(data.get(1)[1].equals("Alice"));
BassertEquals("Alice", data.get(0)[1]);
CassertTrue(data.get(2)[0].equals("Alice"));
DassertEquals("Alice", data.get(1)[0]);
Attempts:
2 left
💡 Hint
Remember that list index 0 is the header row.
🔧 Debug
advanced
2: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();
AThe BufferedReader class is not imported.
BThe file 'data.csv' is not in the project root or working directory.
CThe file 'data.csv' is empty.
DThe FileReader constructor requires an absolute path.
Attempts:
2 left
💡 Hint
Check where the program looks for the file relative to the running location.
framework
advanced
2: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?
AUse a TestNG DataProvider method that reads CSV and supplies data arrays to test methods.
BManually read CSV inside each test method before assertions.
CHardcode CSV data inside test methods as string arrays.
DUse Selenium WebDriver to open CSV files in browser and read data.
Attempts:
2 left
💡 Hint
Think about reusability and separation of test data from test logic.
🧠 Conceptual
expert
3: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?
AUse String.split(",") and then trim quotes manually to fix fields.
BCommas inside quotes are ignored automatically by BufferedReader; no special handling needed.
CSplitting lines by comma directly breaks fields with commas inside quotes; use a CSV parsing library like OpenCSV to handle quoted fields correctly.
DReplace all commas with semicolons before reading to avoid issues.
Attempts:
2 left
💡 Hint
Think about how simple split by comma treats commas inside quotes.