<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Santiago Echavarria</title>
    <description>The latest articles on DEV Community by Santiago Echavarria (@sechavarriar).</description>
    <link>https://dev.to/sechavarriar</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3930156%2Fdf9c6ca6-5217-4211-9648-616db0315ee2.png</url>
      <title>DEV Community: Santiago Echavarria</title>
      <link>https://dev.to/sechavarriar</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/sechavarriar"/>
    <language>en</language>
    <item>
      <title>How I built an AI reporter for Playwright that explains test failures</title>
      <dc:creator>Santiago Echavarria</dc:creator>
      <pubDate>Wed, 13 May 2026 21:50:11 +0000</pubDate>
      <link>https://dev.to/sechavarriar/how-i-built-an-ai-reporter-for-playwright-that-explains-test-failures-5ep</link>
      <guid>https://dev.to/sechavarriar/how-i-built-an-ai-reporter-for-playwright-that-explains-test-failures-5ep</guid>
      <description>&lt;p&gt;After 6 years doing QA automation in Fintech, I got tired of the same cycle:&lt;/p&gt;

&lt;p&gt;Test fails in CI&lt;br&gt;
Download the report&lt;br&gt;
Spend 20 minutes reading stack traces&lt;br&gt;
Realize it was a one-line selector issue&lt;/p&gt;

&lt;p&gt;So I built a custom Playwright reporter that does the debugging for you.&lt;br&gt;
What it does&lt;br&gt;
When a test fails, the reporter automatically:&lt;/p&gt;

&lt;p&gt;Captures the test name, error message, and stack trace&lt;br&gt;
Sends it to an AI with a structured prompt&lt;br&gt;
Gets back a root cause, a TypeScript fix, and a prevention tip&lt;br&gt;
Saves everything to test-results/ai-diagnosis.md&lt;/p&gt;

&lt;p&gt;Here's what the output looks like:&lt;br&gt;
❌ Login › locked out user sees lock message&lt;/p&gt;

&lt;p&gt;🔍 Analyzing failure: "locked out user sees lock message"&lt;/p&gt;




&lt;h2&gt;
  
  
  ❌ locked out user sees lock message
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1. Root cause
&lt;/h3&gt;

&lt;p&gt;The selector &lt;code&gt;[data-test="error"]&lt;/code&gt; matched but the assertion&lt;br&gt;
expected different text than what Sauce Demo returned.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Fix
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;expect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;loginPage&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;errorMessage&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;toContainText&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Epic sadface: Sorry, this user has been locked out.&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  3. Prevention
&lt;/h3&gt;

&lt;p&gt;Always assert the exact error string shown in the UI, not a partial guess.&lt;/p&gt;

&lt;p&gt;📄 Diagnosis saved → test-results/ai-diagnosis.md&lt;br&gt;
The architecture&lt;br&gt;
The key design decision was making the AI provider swappable at runtime via environment variable. No code changes needed — just update your .env:&lt;br&gt;
bash# Free default&lt;br&gt;
AI_PROVIDER=groq&lt;br&gt;
GROQ_API_KEY=your_key&lt;/p&gt;

&lt;h1&gt;
  
  
  Or swap to Claude / OpenAI
&lt;/h1&gt;

&lt;p&gt;AI_PROVIDER=claude&lt;br&gt;
ANTHROPIC_API_KEY=your_key&lt;br&gt;
This is powered by a simple AIProvider interface:&lt;br&gt;
typescriptexport interface AIProvider {&lt;br&gt;
  analyzeFailure(testName: string, error: string): Promise;&lt;br&gt;
}&lt;br&gt;
Each provider (Groq, Claude, OpenAI) implements this interface. The factory reads the env var and returns the right one:&lt;br&gt;
typescriptexport function createProvider(): AIProvider {&lt;br&gt;
  const provider = process.env.AI_PROVIDER ?? 'groq';&lt;br&gt;
  switch (provider) {&lt;br&gt;
    case 'claude': return new ClaudeProvider();&lt;br&gt;
    case 'openai': return new OpenAIProvider();&lt;br&gt;
    default: return new GroqProvider(); // free, no credit card&lt;br&gt;
  }&lt;br&gt;
}&lt;br&gt;
The reporter itself&lt;br&gt;
Playwright lets you build custom reporters by implementing the Reporter interface. The key hook is onTestEnd:&lt;br&gt;
typescriptexport class AIReporter implements Reporter {&lt;br&gt;
  async onTestEnd(test: TestCase, result: TestResult) {&lt;br&gt;
    if (result.status !== 'failed') return;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const provider = createProvider();
const diagnosis = await provider.analyzeFailure(
  test.title,
  result.error?.message ?? 'Unknown error'
);

console.log(`\n🔍 Analyzing failure: "${test.title}"\n`);
console.log(diagnosis);

fs.appendFileSync('test-results/ai-diagnosis.md', diagnosis);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;}&lt;br&gt;
}&lt;br&gt;
Clean and minimal — it only runs when a test fails, so it doesn't slow down passing suites.&lt;br&gt;
The full project structure&lt;br&gt;
The repo also includes a full working example with Sauce Demo:&lt;br&gt;
playwright-ai-reporter/&lt;br&gt;
├── src/ai/&lt;br&gt;
│   ├── AIProvider.interface.ts   # shared contract&lt;br&gt;
│   ├── GroqProvider.ts           # free default&lt;br&gt;
│   ├── ClaudeProvider.ts&lt;br&gt;
│   ├── OpenAIProvider.ts&lt;br&gt;
│   └── providerFactory.ts&lt;br&gt;
├── reporters/&lt;br&gt;
│   └── AIReporter.ts&lt;br&gt;
├── tests/saucedemo/&lt;br&gt;
│   ├── login.spec.ts&lt;br&gt;
│   ├── cart.spec.ts&lt;br&gt;
│   └── checkout.spec.ts&lt;br&gt;
├── pages/                        # Page Object Models&lt;br&gt;
├── fixtures/                     # shared Playwright fixtures&lt;br&gt;
└── .github/workflows/&lt;br&gt;
    └── playwright.yml            # CI already configured&lt;br&gt;
CI with GitHub Actions&lt;br&gt;
The workflow runs on every push. It uploads the HTML report as an artifact always, and uploads ai-diagnosis.md only when there are failures — so you always know exactly what broke and why.&lt;br&gt;
yaml- name: Upload AI diagnosis&lt;br&gt;
  if: failure()&lt;br&gt;
  uses: actions/upload-artifact@v4&lt;br&gt;
  with:&lt;br&gt;
    name: ai-diagnosis&lt;br&gt;
    path: test-results/ai-diagnosis.md&lt;br&gt;
AI provider comparison&lt;br&gt;
ProviderCostSpeedQualityBest forGroq (Llama 3)FreeVery fastGoodPortfolio, small teamsClaude Haiku~$0.001/testFastVery goodMedium teamsClaude Sonnet~$0.005/testMediumExcellentEnterpriseGPT-4o-mini~$0.003/testFastVery goodAlternative&lt;br&gt;
I use Groq for local dev (free tier is more than enough) and would use Claude Sonnet for a production CI pipeline where diagnosis quality matters.&lt;br&gt;
What's next&lt;br&gt;
A few things I want to add:&lt;/p&gt;

&lt;p&gt;Screenshot attachment in the diagnosis when available&lt;br&gt;
Grouping repeated failures to avoid duplicate AI calls&lt;br&gt;
Slack/Teams notification with the diagnosis embedded&lt;/p&gt;

&lt;p&gt;Try it yourself&lt;br&gt;
bashgit clone &lt;a href="https://github.com/sechavarriar/playwright-ai-reporter" rel="noopener noreferrer"&gt;https://github.com/sechavarriar/playwright-ai-reporter&lt;/a&gt;&lt;br&gt;
cd playwright-ai-reporter&lt;br&gt;
npm install&lt;br&gt;
npx playwright install chromium&lt;br&gt;
cp .env.example .env&lt;/p&gt;

&lt;h1&gt;
  
  
  Add your free Groq key from console.groq.com
&lt;/h1&gt;

&lt;p&gt;npm test&lt;br&gt;
The repo is at &lt;a href="https://github.com/sechavarriar/playwright-ai-reporter" rel="noopener noreferrer"&gt;https://github.com/sechavarriar/playwright-ai-reporter&lt;/a&gt; — feedback and PRs very welcome. Especially curious if anyone has ideas for handling flaky tests differently.&lt;/p&gt;

</description>
      <category>ai</category>
      <category>automation</category>
      <category>showdev</category>
      <category>testing</category>
    </item>
  </channel>
</rss>
