Challenge - 5 Problems
CSV Test Data Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of reading CSV test data with Python csv.reader
What will be the output of this code snippet that reads a CSV file and prints each row as a list?
Selenium Python
import csv with open('testdata.csv', newline='') as csvfile: reader = csv.reader(csvfile) for row in reader: print(row)
Attempts:
2 left
💡 Hint
csv.reader returns each row as a list of strings.
✗ Incorrect
The csv.reader reads the CSV file line by line and splits each line by commas into a list. So each printed row is a list of strings representing the columns.
❓ assertion
intermediate1:30remaining
Correct assertion for CSV test data length
Given a list 'data' read from a CSV file with 3 rows including header, which assertion correctly checks the number of data rows excluding the header?
Selenium Python
data = [['username', 'password'], ['user1', 'pass1'], ['user2', 'pass2']]
Attempts:
2 left
💡 Hint
Remember to exclude the header row when counting data rows.
✗ Incorrect
The header row is the first element, so data rows are from index 1 onward. len(data) is 3, so len(data) - 1 equals 2 data rows.
❓ locator
advanced1:30remaining
Best locator to find username input for CSV-driven test
In a Selenium test reading usernames from CSV, which locator is best to find the username input field for entering data?
Attempts:
2 left
💡 Hint
ID locators are unique and fast.
✗ Incorrect
Using ID is the most reliable and fastest locator if the element has a unique ID attribute.
🔧 Debug
advanced2:00remaining
Identify error reading CSV with DictReader
What error will this code raise when reading a CSV file missing the header row?
Selenium Python
import csv with open('testdata_noheader.csv', newline='') as csvfile: reader = csv.DictReader(csvfile) for row in reader: print(row['username'])
Attempts:
2 left
💡 Hint
DictReader uses the first row as keys by default.
✗ Incorrect
If the CSV file has no header row, DictReader treats the first data row as header keys, so 'username' key is missing and accessing row['username'] raises KeyError.
❓ framework
expert3:00remaining
Best practice for integrating CSV test data in Selenium Python tests
Which approach best integrates CSV test data into Selenium tests for multiple login scenarios?
Attempts:
2 left
💡 Hint
Use test frameworks features to run tests with multiple data sets.
✗ Incorrect
Using pytest parametrize with CSV data read once in setup allows clean, reusable, and scalable tests for multiple data-driven scenarios.