◉CLAUDE LABJP
●SONNET 4.5 — Sonnet 4.5 was retired from the Claude API on 11/30. Calls now return an error. Move to Sonnet 5.5●PROJECTS — The Enterprise Analytics API now reports daily usage for the new projects experience (beta)●OPUS 4.5 — claude-opus-4-5 retires on 2027/1/22, 52 days from now. The replacement is claude-opus-5-5●LANGUAGE — Some users say Claude switches to another language mid-session while they write in English●NEW — New: Weekly usage looks like it jumped right after a plan upgrade? Check this first●COWORK — Handing Cowork a folder for the first time? Start with a task that only reads files●SONNET 4.5 — Sonnet 4.5 was retired from the Claude API on 11/30. Calls now return an error. Move to Sonnet 5.5●PROJECTS — The Enterprise Analytics API now reports daily usage for the new projects experience (beta)●OPUS 4.5 — claude-opus-4-5 retires on 2027/1/22, 52 days from now. The replacement is claude-opus-5-5●LANGUAGE — Some users say Claude switches to another language mid-session while they write in English●NEW — New: Weekly usage looks like it jumped right after a plan upgrade? Check this first●COWORK — Handing Cowork a folder for the first time? Start with a task that only reads files
Articles/Claude Code
⟐ Claude Code/2026-03-28Advanced

Running Claude Code × Playwright E2E Tests in Production — Pitfalls and Decision Criteria

Implementation patterns for running E2E tests with Claude Code and Playwright in production, plus how to measure whether the investment pays back. Includes the Cloudflare Workers and Pages preview deployment pitfalls, and a decision framework that indie developers can use to judge whether E2E tests are worth the investment.

playwrighte2e-testingautomation110claude-code135testing6

✦ Premium Article

Across years of building and running apps on my own, the same regret has repeated itself: "if I had written the E2E test before this release, that production incident would have been prevented." Writing and maintaining test code is heavy work, and as an indie developer it has never been realistic to put the same effort into tests as into production code.

That changed when I started combining Claude Code with Playwright. E2E testing finally turned from a sunk cost into an investment. This article gathers what I measured and what I tripped over while rolling this stack out gradually across my own sites.

If I had to name the one thing that changed, it was not the number of tests. It was being able to trust that a red run meant a real bug. Getting there took a detour: for a while I accepted whatever Claude Code wrote, and the suite became flakier, not steadier.

What follows covers what to record from day one so you can tell whether the investment is paying back, the mistakes that slip into generated test code, and the framework I use as an indie developer to decide whether E2E testing is worth it. The code was checked against the Playwright 1.65 line and the GitHub Actions docs as of November 2026.


The First 30 Minutes — Installing Playwright and Wiring It to Claude Code

I picked Playwright for one reason: it drives Chrome, Firefox, and Safari engines from a single config file. Having shipped two Safari-only layout bugs to production, being able to reproduce WebKit locally settled the decision for me. Start with the minimum setup that Claude Code needs to work against.

Installing and Configuring Playwright

npm install --save-dev @playwright/test
npx playwright install
 
# Generate and configure playwright.config.ts

After installing Playwright, create your playwright.config.ts configuration file—this becomes the nerve center for all test execution.

import { defineConfig, devices } from '@playwright/test';
 
export default defineConfig({
  testDir: './tests/e2e',
  fullyParallel: true,
  forbidOnly: !!process.env.CI,
  retries: process.env.CI ? 2 : 0,
  workers: process.env.CI ? 1 : undefined,
  reporter: [
    ['html', { outputFolder: 'playwright-report' }],
    ['json', { outputFile: 'test-results/results.json' }],
    ['junit', { outputFile: 'test-results/junit.xml' }],
  ],
  use: {
    baseURL: 'http://localhost:3000',
    trace: 'on-first-retry',
    screenshot: 'only-on-failure',
  },
  projects: [
    {
      name: 'chromium',
      use: { ...devices['Desktop Chrome'] },
    },
    {
      name: 'firefox',
      use: { ...devices['Desktop Firefox'] },
    },
    {
      name: 'webkit',
      use: { ...devices['Desktop Safari'] },
    },
  ],
  webServer: {
    command: 'npm run dev',
    url: 'http://localhost:3000',
    reuseExistingServer: !process.env.CI,
  },
});

This foundational configuration enables Claude Code to reference your test environment and generate appropriately-scoped test suites on subsequent requests.

Creating Reusable Claude Code Prompt Templates

To maximize efficiency with Claude Code, prepare standardized prompt templates that you'll refine over time.

# Playwright Test Code Generation Prompt
 
You are a Playwright testing expert. Generate test code based on the following requirements.
 
## Requirements
- Component/Page to test: [COMPONENT_NAME]
- Test scenarios:
  1. [Scenario 1]
  2. [Scenario 2]
 
## Standards
- Adopt Page Object pattern
- Use data-testid attributes for element selection
- Explicitly define wait strategies (no hardcoded sleeps)
- Include localization support if multi-language needed
- Include accessibility (a11y) checks
 
## Output Format
- Test file path: tests/e2e/[name].spec.ts
- Page Object file: tests/pages/[Name]Page.ts

Providing this template to Claude Code ensures consistent, high-quality test generation every time.


How to Measure Cost and Payback

The setup above is well documented in the Playwright and Claude Code references. What is not documented is whether the setup actually pays back once it meets production. I started without recording anything, and three months later I could not answer the simple question "is this working?" These are the metrics I now record from the first day, and how I collect them.

Four metrics worth recording

MetricHow to collect itHow to read it
Flaky rateTests whose JSON reporter status is flaky (passed on retry) ÷ all tests, appended after each nightly runWatch the trend. Don't aim for zero
Time per Page ObjectFrom asking Claude Code to merging after reviewInclude review time; generation time alone is misleading
Bugs stopped before deployFor each red run that was a real bug, one line written by handOne a month is enough to justify the upkeep
CI time per runThe job duration in GitHub ActionsIf waiting on PRs feels slow, parallelize or narrow the scope

The flaky rate was the inflection point. It moved E2E tests from "noisy, no one looks" to "if it's red, it's a real bug." Chasing zero by piling on waits makes the suite slow and dull, and a dull suite hides production regressions instead of catching them.

The three Claude Code prompts I keep returning to

I store reusable prompts under .claude/commands/ in each repo so changes are tracked in Git. The three I rely on most are:

  1. Page Object autogeneration prompt — Given a Figma frame link and the data-testid naming convention, Claude Code produces a full Page Object class. Even with review included, it now takes me less time than writing one by hand.
  2. Flaky diagnosis prompt — Given the JSON results of the last 10 CI runs, Claude Code classifies the root cause (network / animation / timing / state leak) and returns a patch. I hit the same kind of flake twice far less often than before.
  3. Visual diff triage prompt — Given a list of *-diff.png filenames and pixel deltas, Claude Code returns a classification (allowable vs. real bug) plus a diff for the mask: config.

Of those, the flaky diagnosis prompt is the highest leverage one for indie developers. The full template lives in the "Automatic Flaky Test Diagnosis and Repair" section below.

The kinds of bugs it stopped before deploy

Looking back, the bugs the suite stopped before a production deploy clustered into four kinds. If you are deciding where to start, this may help:

  • Payment flow regressions (failing to reach Stripe Checkout)
  • The previous language lingering after a locale switch (next-intl)
  • Membership eligibility edge cases
  • Missing translation keys breaking the layout

In my AdMob app business, I have seen many times what happens when the payment flow breaks for even an hour. Revenue stops the moment Stripe Checkout cannot load. If you run a paid membership on a personal project, prioritize the payment flow in your E2E suite above everything else.


✦

Thank you for reading this far.

Continue Reading

What follows includes implementation code, benchmarks, and practical content we hope you'll find useful. This site runs without ads — server and development costs are supported entirely by members like you. If it's been helpful, we'd be truly grateful for your support.

WHAT YOU'LL LEARN
✦Mistakes that slip into generated tests (networkidle, toHaveCount with a regex, looping reruns) and how to fix them
✦A triage table for tests that fail only on CI, plus a GitHub Actions workflow aligned with Playwright 1.65 and the v6 actions
✦Why E2E breaks around Cloudflare Pages preview URLs, Stripe Checkout and locale switches, with fix code
Secure payment via Stripe · Cancel anytime
✦

Unlock This Article

Get full access to the rest of this article. Buy once, read anytime. This site is ad-free — your support goes directly toward keeping it running.

or
Unlock all articles with Membership →
Share

Thank You for Reading

Claude Lab is ad-free, supported entirely by members like you. We publish practical guides daily with implementation code, benchmarks, and production-ready patterns. If you've found it useful, we'd love to have you on board.

  • ✦Copy-paste ready implementation code
  • ✦New advanced guides published daily
  • ✦$5/mo or $10 for lifetime access
View Membership →

Related Articles

⟐ Claude Code2026-04-30
Composing Claude Code Skills — Building Automation a Single Skill Can't Reach
A practical guide to going beyond one-skill-at-a-time and composing multiple Claude Code Skills into real workflows. Pipeline, branching, and meta-skill patterns with full implementation examples and the failure modes you should design against.
⟐ Claude Code2026-03-24
How to Automate Game Development with Claude Code × unity-mcp — A Complete Workflow from Concept to Release
Learn how to combine Claude Code with unity-mcp to automate Unity game development. The hcg-workflows skill set provides an 8-phase workflow from planning to deployment.
⟐ Claude Code2026-11-10
How Far Behind Is Your Claude Code on the stable Channel? I Counted Published Versions Instead of Subtracting Numbers
Subtracting version numbers overstates the gap between stable and latest. Here is a short Python script that counts published versions from the npm registry, plus the channel settings worth knowing.