Playwright Python 10 | Data Driven Testing

Publicado el: 08 julio 2025
en el canal de: Automation Step by Step
10,048
136

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  


En esta página del sitio puede ver el video en línea Playwright Python 10 | Data Driven Testing de Duración hora minuto segunda en buena calidad , que subió el usuario Automation Step by Step 08 julio 2025, comparta el enlace con amigos y conocidos, en youtube este video ya ha sido visto 10,048 veces y le gustó 136 a los espectadores. Disfruta viendo!