Frontend Development 4 min read

Playwright Automation Script for End-to-End H5 User Flow (Registration, Login, Checkout)

This tutorial provides a complete Playwright Python script that automates a typical H5 e‑commerce user journey—including registration, login, address entry, product selection, cart addition, checkout, order review, and screenshot capture—while explaining how to adapt URLs and selectors for your own site.

Test Development Learning Exchange
Test Development Learning Exchange
Test Development Learning Exchange
Playwright Automation Script for End-to-End H5 User Flow (Registration, Login, Checkout)

This example demonstrates an end‑to‑end Playwright automation script for an H5 web application, covering user registration, login, address entry, browsing the home page, selecting a product, adding it to the cart, completing payment, and viewing the order.

The script launches a Chromium browser, creates a new context and page, then sequentially navigates to each required URL, fills form fields with page.fill() , clicks buttons with page.click() , captures a screenshot, and finally closes the browser.

from playwright import sync_playwright

def run_playwright_script():
    # Launch browser
    with sync_playwright() as playwright:
        browser = playwright.chromium.launch()
        context = browser.new_context()
        page = context.new_page()

        # User registration
        page.goto('https://www.example.com/register')
        page.fill('input[name="username"]', 'myusername')
        page.fill('input[name="password"]', 'mypassword')
        page.click('button[type="submit"]')

        # User login
        page.goto('https://www.example.com/login')
        page.fill('input[name="username"]', 'myusername')
        page.fill('input[name="password"]', 'mypassword')
        page.click('button[type="submit"]')

        # Fill address
        page.goto('https://www.example.com/address')
        page.fill('input[name="address"]', '123 Street, City')
        page.fill('input[name="phone"]', '1234567890')
        page.click('button[type="submit"]')

        # Visit home page
        page.goto('https://www.example.com')

        # Select product
        page.click('a[href="/products"]')
        page.click('a[data-product-id="1"]')

        # Add to cart
        page.click('button[data-action="add-to-cart"]')

        # Checkout
        page.goto('https://www.example.com/checkout')
        page.fill('input[name="card-number"]', '1234567890123456')
        page.fill('input[name="expiry-date"]', '12/24')
        page.fill('input[name="cvv"]', '123')
        page.click('button[type="submit"]')

        # View orders
        page.goto('https://www.example.com/orders')

        # Screenshot
        page.screenshot(path='screenshot.png')

        # Close browser
        browser.close()

run_playwright_script()

Replace https://www.example.com with the actual URL of the H5 page you are testing and adjust field names and selectors to match your page’s markup.

frontendPythonautomationPlaywrightweb testingE2E
Test Development Learning Exchange
Written by

Test Development Learning Exchange

Test Development Learning Exchange

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.