Overview: Architecture of POM Test Suites
In an enterprise Playwright Python framework, test cases consume page objects via custom pytest fixtures. This prevents instantiation overhead and keeps code isolated. Below are 15 real-world production examples covering authentication, catalog filtering, cart transactions, user profiles, error handling, and test suite execution.
expect() assertions.
Example 1: Multi-Page Fixture Configuration
File: conftest.py — Centralized fixture injection for all page objects.
import pytest
from pages.login_page import LoginPage
from pages.products_page import ProductsPage
from pages.cart_page import CartPage
@pytest.fixture
def login_page(page):
return LoginPage(page)
@pytest.fixture
def products_page(page):
return ProductsPage(page)
@pytest.fixture
def cart_page(page):
return CartPage(page)
Example 2: Standard User Login Test Case
File: tests/test_auth.py — Verifies valid credentials routing to the dashboard.
from playwright.sync_api import expect
def test_standard_user_login(login_page, page):
login_page.navigate()
login_page.login("standard_user", "secret_sauce")
expect(page).to_have_url("/inventory.html")
expect(login_page.header_title).to_have_text("Products")
Example 3: Invalid Login Error Assertion Test
File: tests/test_auth.py — Validates lockout and error feedback components.
from playwright.sync_api import expect
def test_locked_out_user_error(login_page):
login_page.navigate()
login_page.login("locked_out_user", "secret_sauce")
expect(login_page.error_banner).to_be_visible()
expect(login_page.error_banner).to_contain_text("Sorry, this user has been locked out")
Example 4: Empty Fields Validation Test
File: tests/test_auth.py — Ensures login prevents submission on blank inputs.
from playwright.sync_api import expect
def test_empty_credentials_validation(login_page):
login_page.navigate()
login_page.click_login_button()
expect(login_page.error_banner).to_be_visible()
expect(login_page.error_banner).to_contain_text("Username is required")
Example 5: Catalog Product Search Test Case
File: tests/test_catalog.py — Searches for specific items using the products page object.
from playwright.sync_api import expect
def test_search_and_locate_backpack(login_page, products_page, page):
login_page.navigate()
login_page.login("standard_user", "secret_sauce")
products_page.search_item("Sauce Labs Backpack")
expect(products_page.get_product_card("Sauce Labs Backpack")).to_be_visible()
Example 6: Sorting Products by Price (Low to High)
File: tests/test_catalog.py — Tests sort dropdown behavior via POM method.
from playwright.sync_api import expect
def test_sort_products_low_to_high(login_page, products_page):
login_page.navigate()
login_page.login("standard_user", "secret_sauce")
products_page.select_sort_option("Price (low to high)")
first_price = products_page.get_first_product_price()
assert float(first_price.replace("$", "")) == 7.99
Example 7: Adding Items to Shopping Cart Suite
File: tests/test_cart.py — Validates badge increments upon adding stock.
from playwright.sync_api import expect
def test_add_item_to_cart_badge_update(login_page, products_page):
login_page.navigate()
login_page.login("standard_user", "secret_sauce")
products_page.add_to_cart_by_name("Sauce Labs Bike Light")
expect(products_page.cart_badge).to_have_text("1")
Example 8: Cart Item Verification & Removal Test
File: tests/test_cart.py — Navigates to cart and removes an added item.
from playwright.sync_api import expect
def test_remove_item_from_cart(login_page, products_page, cart_page):
login_page.navigate()
login_page.login("standard_user", "secret_sauce")
products_page.add_to_cart_by_name("Sauce Labs Bolt T-Shirt")
products_page.open_cart()
cart_page.remove_item("Sauce Labs Bolt T-Shirt")
expect(cart_page.cart_items).to_have_count(0)
Example 9: Checkout Customer Information Suite
File: tests/test_checkout.py — Fills shipping form fields using POM methods.
from playwright.sync_api import expect
def test_checkout_shipping_form(login_page, products_page, cart_page):
login_page.navigate()
login_page.login("standard_user", "secret_sauce")
products_page.add_to_cart_by_name("Sauce Labs Onesie")
products_page.open_cart()
cart_page.Proceed_to_checkout()
cart_page.fill_shipping_details("John", "Doe", "90210")
expect(cart_page.checkout_summary_title).to_have_text("Checkout: Overview")
Example 10: Order Completion & Confirmation Verification
File: tests/test_checkout.py — Completes full purchase workflow.
from playwright.sync_api import expect
def test_complete_order_success(login_page, products_page, cart_page):
login_page.navigate()
login_page.login("standard_user", "secret_sauce")
products_page.add_to_cart_by_name("Sauce Labs Fleece Jacket")
products_page.open_cart()
cart_page.Proceed_to_checkout()
cart_page.fill_shipping_details("Alice", "Smith", "10001")
cart_page.finish_order()
expect(cart_page.success_header).to_have_text("Thank you for your order!")
Example 11: Parameterized Login Test Suite
File: tests/test_parameterized.py — Runs multiple user roles using pytest marks and POM.
import pytest
from playwright.sync_api import expect
@pytest.mark.parametrize("username,expected_url", [
("standard_user", "/inventory.html"),
("problem_user", "/inventory.html"),
("performance_glitch_user", "/inventory.html")
])
def test_users_successful_login(login_page, page, username, expected_url):
login_page.navigate()
login_page.login(username, "secret_sauce")
expect(page).to_have_url(expected_url)
Example 12: User Profile Settings Update Suite
File: tests/test_profile.py — Updates user settings through account page abstraction.
from playwright.sync_api import expect
def test_update_shipping_address_profile(login_page, profile_page):
login_page.navigate()
login_page.login("standard_user", "secret_sauce")
profile_page.navigate_to_settings()
profile_page.update_phone_number("555-0199")
expect(profile_page.toast_success_message).to_be_visible()
Example 13: Product Review & Rating Submission Test
File: tests/test_reviews.py — Interacts with modal overlays inside page classes.
from playwright.sync_api import expect
def test_submit_product_review(login_page, products_page):
login_page.navigate()
login_page.login("standard_user", "secret_sauce")
products_page.open_product_details("Sauce Labs Backpack")
products_page.submit_star_rating(5, "Amazing quality backpack!")
expect(products_page.review_confirmation).to_contain_text("Review submitted successfully")
Example 14: Session Logout Validation Test
File: tests/test_auth.py — Tests menu drawer navigation and session termination.
from playwright.sync_api import expect
def test_user_logout_flow(login_page, products_page, page):
login_page.navigate()
login_page.login("standard_user", "secret_sauce")
products_page.open_sidebar_menu()
products_page.click_logout_link()
expect(page).to_have_url("/")
expect(login_page.login_button).to_be_visible()
Example 15: Executing Smoke Test Suite via CLI with POM
File: pytest.ini & Terminal Execution — Grouping and running critical user journeys.
[pytest]
base_url = https://www.saucedemo.com
addopts = -v --browser chromium
markers =
smoke: core verification suite
regression: full suite checks
# Run command in terminal:
# pytest -m smoke -v