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
—
Auf dieser Seite können Sie das Online-Video Playwright Python 10 | Data Driven Testing mit der Dauer stunde minuten sekunde in guter Qualität ansehen, das der Benutzer Automation Step by Step 08 Juli 2025 hochgeladen hat, den Link mit Freunden und Bekannten teilen, dieses Video wurde auf Youtube bereits 10,048 Mal angesehen und es wurde von 136 den Zuschauern gefallen. Viel Spaß beim Betrachtenden Zuschauern gefallen!