u/Ill-Block9349

Built an AI-powered Playwright reporter that explains WHY your tests failed (free, no credit card)

Hey everyone,

Hey Playwright folks, one thing that always slowed me down was spending 20–30 min debugging a failed test just to find out it was a one-line selector issue.

So I built this: a custom Playwright reporter that hooks into onTestEnd, sends the failure context to an AI, and gets back a structured diagnosis with:

  • Root cause of the failure
  • Exact fix with a TypeScript code snippet
  • Prevention tip so it doesn't happen again
  • Saves everything to ai-diagnosis.md automatically

Example output:

❌ Login › locked out user sees lock message

🔍 Analyzing failure...

## Root cause
The selector `[data-test="error"]` matched but the assertion
expected different text than what Sauce Demo returned.

## Fix
await expect(loginPage.errorMessage).toContainText(
  'Epic sadface: Sorry, this user has been locked out.'
);

## Prevention
Always assert the exact error string shown in the UI, not a partial guess.

It uses Groq by default (completely free, no credit card). You can also swap to Claude or OpenAI with a single env variable — no code changes needed.

The repo also includes:

  • Full Page Object Model structure
  • Shared fixtures to avoid login boilerplate
  • GitHub Actions CI already configured
  • .env.example with all keys documented

Repo: https://github.com/sechavarriar/playwright-ai-reporter

Would love feedback — especially if anyone has used similar approaches or knows how to make the AI diagnosis more accurate for flaky tests. Happy to answer questions!

reddit.com
u/Ill-Block9349 — 1 day ago