Playwright + Python · Lesson 28 of 37
Module 28: Test Data
Your task
Implement generate_random_user_payload():
Write it in the editor, then press Check answer (Ctrl + Enter).
import pytest
@pytest.mark.parametrize("username,password,expected_error", [
("invalid_user", "Secret123", "User not found"),
("admin@targetqa.com", "wrong_pass", "Invalid password"),
("", "Secret123", "Username required"),
])
def test_login_validation_errors(page, username, password, expected_error):
page.goto("https://targetqa.com/login")
page.get_by_label("Username").fill(username)
page.get_by_label("Password").fill(password)
page.get_by_role("button", name="Log In").click()
expect(page.locator(".error-banner")).to_contain_text(expected_error)Testing multiple input combinations with one test function is simple in Python. In this lesson, you will master @pytest.mark.parametrize, loading external JSON fixtures, and generating dynamic random data. Let's master test data!
Part of the Playwright + Python course (Playwright with Python). Practice this concept live in the Playwright Online Compiler or explore our free automation practice form.
Yes! You can load JSON data into a list of tuples and pass that list directly to @pytest.mark.parametrize.
Ready? Solve the task in the editor
Use Check answer to mark it complete. Hints are there if you need them.
___