In this session…
How to parameterize tests
How to get data from csv file
How to get data from json file
DEMO - How to do Data Driven Testing
Step 1 - Create a simple test that uses some data
Step 2 - Parameterize the test i.e. use variables in place of hard coded data values
pass values to the variables using @pytest.mark. parameterize() fixture
Using CSV File
Step 3 - Now store the test data in a csv file
Step 4 - In the test file create function to read and get data from csv file
Using JSON File
Step 5 - Create a json file and add the test data
Step 6 - In the test file create function to read and get data from json file
-
Function to get data from csv file
import csv
def get_csv_data():
data = []
with open("data.csv", newline="") as csvfile:
reader = csv.DictReader(csvfile)
for row in reader:
data.append((row["search_term"], row["expected_keyword"]))
return data
@pytest.mark.parametrize("username, password", get_csv_data())
def test_example(page: Page, username, password) -> None:
JSON file
[
{
"username": "Admin",
"password": "admin123"
},
{
"username": "Test1",
"password": "admin345"
},
{
"username": "Test2",
"password": "admin567"
}
]
Function to get data from json file
import json
def get_json_data():
with open("data.json") as f:
raw = json.load(f)
return [(item["search_term"], item["expected_keyword"]) for item in raw]
@pytest.mark.parametrize("username, password", get_json_data())
def test_example(page: Page, username, password) -> None:
GitHub Repo - https://github.com/Raghav-Pal/Playwri...
▬▬▬▬▬▬▬
Share with all who may need this
If my work has helped you, consider helping any animal near you, in any way you can
Never Stop Learning
Raghav Pal
▬▬▬▬ USEFUL LINKS ▬▬▬▬
✅ ALL TUTORIALS - https://AutomationStepByStep.com/
QnA Friday - https://bit.ly/2NgwGpw
Sunday Special - https://bit.ly/2wB23BO
🙌 Connect with Raghav:
Ask Raghav: https://bit.ly/2CoJGWf
GitHub: https://github.com/Raghav-Pal
Udemy: https://www.udemy.com/user/raghav-pal-3/
Shorts Eng - https://bit.ly/3H9bifV
Shorts Hindi - https://bit.ly/3XY7XqN
➡️ Subscribe for more videos: / @raghavpal
—
On this page of the site you can watch the video online Playwright Python 10 | Data Driven Testing with a duration of hours minute second in good quality, which was uploaded by the user Automation Step by Step 08 July 2025, share the link with friends and acquaintances, this video has already been watched 10,048 times on youtube and it was liked by 136 viewers. Enjoy your viewing!