Pytest-Playwright E2E Forge — Python Tests That Don't Flake

    by Mika Nekote

    1

    Generate pytest-playwright E2E tests the way stable suites are actually built: Python Page Objects, one shared login, semantic locators, zero sleeps — and a repeat-run flake check before anything is called done.

    $12

    Secure checkout via Stripe

    Money-back guarantee

    Converts to your local currency at checkout

    Security scanned

    Works with the AI Agents you already use

    Pytest-Playwright E2E Forge — Python Tests That Don't Flake

    Example session with this skill installed

    Generate an E2E test for our login flow. The login page has email and password fields, and a "Sign In" button. After login, the user should see a heading that says "Welcome to Dashboard".

    • Read your context and instructions
    • Compiled the pytest-playwright e2e forge

    I have generated the Page Object and test file for the login flow. A specialized conftest.py has been created to handle environment-based credentials and failure artifacts.

    E2E Login Flow Implementation

    
    # tests/pages/login_page.py
    from playwright.sync_api import Page, expect
    
    class LoginPage:
        def __init__(self, page: Page):
            self.page = page
            self.email_input = page.get_by_label("Email")
            self.password_input = page.get_by_label("Password")
            self.sign_in_button = page.get_by_role("button", name="Sign In")
    
        def login(self, email: str, password: str):
            self.email_input.fill(email)
            self.password_input.fill(password)
            self.sign_in_button.click()
            # Wait for dashboard transition
            expect(self.page).to_have_url(".*/dashboard")
    
    # tests/test_auth.py
    import os
    import pytest
    from playwright.sync_api import Page, expect
    from .pages.login_page import LoginPage
    
    def test_login_shows_dashboard(page: Page):
        """Test that a user can log in with valid credentials."""
        login_page = LoginPage(page)
        
        # Credentials from environment variables
        user = os.environ.get("E2E_USER")
        password = os.environ.get("E2E_PASSWORD")
        
        page.goto("/login")
        login_page.login(user, password)
        
        # Observable end state
        dashboard_heading = page.get_by_role("heading", name="Welcome to Dashboard")
        expect(dashboard_heading).to_be_visible()
    

    Flake Check Results

    • test_login_shows_dashboard: stable-pass (5/5 runs)

    Next steps

    1. Ensure E2E_USER and E2E_PASSWORD are set in your local environment or CI secrets.
    2. Run pytest --base-url <your-app-url> --browser chromium to execute the suite.
    3. Review the test-results/ directory if you encounter any failures to see traces and logs.

    Connects securely to your tools. The creator never sees your data.

    About this skill

    Most Playwright test generators target TypeScript. If your backend is Python — FastAPI, Django, Flask — you end up translating someone else's patterns and inheriting their flakes.

    Pytest-Playwright E2E Forge is a skill that makes your agent generate E2E tests natively for pytest-playwright, following the practices that keep suites green:

    • Flow selection first. It covers user-critical flows (sign-in, the main transaction, destructive actions, permission boundaries) instead of spraying tests at every page.
    • Python Page Objects. One class per screen, locators as properties, user-level actions — generated from a battle-tested template.
    • Log in once, not per test. A session-scoped fixture logs in through the UI a single time and reuses Playwright storage_state everywhere else, with an optional second low-privilege account for permission tests.
    • Semantic locators, enforced. Role → label → placeholder → text → test id. CSS/XPath chains, generated class names, sleep(), and one-shot state reads are on a reject list the agent must apply.
    • Failure evidence built in. Screenshot + browser console log on every failure, plus the exact flags for traces and video.
    • Verified, not just generated. The bundled flake_check.py runs every new test N times in separate processes and classifies it stable-pass / stable-fail / FLAKY. A suite isn't "done" until everything delivered is stable-pass.

    What's included:

    • SKILL.md — The full workflow: flow selection → conftest → Page Objects → tests → anti-flake rules → verification
    • assets/conftest_template.py — Drop-in conftest: storage_state auth fixtures (two accounts), console capture, failure artifacts
    • assets/page_object_template.py — Page Object template with worked locator examples
    • reference/locator-rules.md — Locator priority order + anti-pattern table
    • scripts/flake_check.py — Repeat-run flake detector (stdlib only, JSON report)
    • examples/ — Complete worked example: login + project-list flow

    Who it's for: Python web teams and solo developers who want browser tests that still pass next month — especially if your E2E layer is currently empty, Selenium-era, or a pile of translated TypeScript examples.

    Requirements: Python 3.10+, pytest, playwright, pytest-playwright; a reachable non-production environment and a dedicated test account; an agent that can read SKILL.md-style skill packages.

    Sync API only. No support for visual regression or live data feeds. Requires environment variables for credentials and a dedicated test account.

    How to use

    1. 1

      Connect your agent to the Agensi MCP

      Copy the prompt and paste it into Claude, ChatGPT, Cursor or any agent that supports MCP. It sets up the connection for you. Manual setup

    2. 2

      Sign in to Agensi

      Your agent shows a sign-in link. Sign in and click Allow.

    3. 3

      Ask for what you need

      Your agent loads this skill and uses it on your task. It always asks before buying a skill.

    Reviews

    No reviews yet

    Be one of the first to try it. Every listed skill goes through the trust checks below.

    Security scanned

    Checked by our 8-point scan before listing

    Fresh listing

    Recently published to Agensi

    Money-back guarantee

    Doesn't do what its page promises? You get your money back.

    Trust & safety

    Security scan

    Security scan passed 9 days ago

    Software
    Python

    Permissions

    Terminal / Shell
    Browser
    Read Files
    Write Files
    Environment Variables
    Listed9 days ago

    What's inside

    Creator

    M

    Mika Nekote

    2 skills on Agensi

    Frequently Asked Questions

    No. It's a workflow skill plus working code assets.

    Any Python web app reachable over HTTP with a login flow.

    Codegen records CSS-heavy, sleep-prone scripts. This skill generates maintainable Page Objects with semantic locators and then proves stability by running each test repeatedly.

    Yes. Headless-friendly, credentials from environment variables, flake_check.py exits non-zero on flaky tests.

    No — deliberately Python sync-API pytest-playwright only.

    New in Testing & Debugging

    Find more skills like this on the Claude Skills Marketplace, the Codex Skills Marketplace and the Gemini Skills Marketplace, or browse Claude Skills for Testing & Debugging.