0
0
Selenium Pythontesting~3 mins

Why Reading test data from CSV in Selenium Python? - Purpose & Use Cases

Choose your learning style9 modes available
The Big Idea

What if you could test hundreds of users without typing a single username by hand?

The Scenario

Imagine testing a website login form by typing usernames and passwords manually every time you run a test.

You have dozens of user accounts to check, and you write each one by hand in your test script.

The Problem

Manually entering test data is slow and boring.

It is easy to make mistakes like typos or forgetting to update data.

When you want to test many users, it becomes a huge pain and wastes time.

The Solution

Reading test data from a CSV file lets your test script load many user details automatically.

This means you write the data once in a simple file, and your tests use it again and again without errors.

Before vs After
Before
username = 'user1'
password = 'pass1'
# Repeat for each user manually
After
import csv
with open('users.csv', newline='') as file:
    reader = csv.DictReader(file)
    for row in reader:
        username = row['username']
        password = row['password']
What It Enables

You can run many tests quickly and reliably by loading data from files instead of typing it every time.

Real Life Example

Testing a shopping site login with 100 different user accounts stored in a CSV file, so you can check all logins in one go without rewriting tests.

Key Takeaways

Manual data entry is slow and error-prone.

CSV files store test data cleanly and simply.

Reading CSV data automates and speeds up testing.