AI-Driven Test Automation Pipeline

Jason

Jason Tur

๐Ÿš€ AI Playwright Test Lab

An end-to-end AI-powered test automation pipeline that:
โœ”๏ธ Generates Playwright tests from plain-English user stories
โœ”๏ธ Runs your Playwright suite
โœ”๏ธ Analyzes failed tests using AI, producing explanations, root causes, fix suggestions, and flakiness tips
โœ”๏ธ Builds a beautifully styled HTML dashboard of all AI results
โœ”๏ธ One-command workflow using npm run ai:flow

๐Ÿ“ธ Demo Overview

This workflow turns simple input like:
stories/login.md
As a user, I want to log in with valid credentials so I can access my dashboard.

Acceptance:
- Navigate to login page
- Enter valid email/password
- Click login
- Expect dashboard to load

Into:
A generated Playwright test
A full run
AI failure analysis
A glowing, animated HTML dashboard like this:
ai-report.html (auto-opens):
Plain English explanation
Root cause analysis
Suggested test fixes
Flakiness mitigation
Styled cards, badges, gradients, animations

๐Ÿ”ง Tech Stack

Node.js + ES Modules
Playwright (@playwright/test)
OpenAI API (GPT-4.1)
Custom HTML reporting with external CSS
Dark-mode dashboard UI

๐Ÿ“‚ Project Structure

ai_project/
โ”‚
โ”œโ”€โ”€ stories/
โ”‚ โ””โ”€โ”€ login.md # Your natural language test cases
โ”‚
โ”œโ”€โ”€ tests/
โ”‚ โ””โ”€โ”€ login.spec.js # Auto-generated Playwright test
โ”‚
โ”œโ”€โ”€ analyze/
โ”‚ โ”œโ”€โ”€ analyzeFailures.js # AI engine (JSON + HTML dashboard)
โ”‚ โ””โ”€โ”€ ... # (additional helper files optional)
โ”‚
โ”œโ”€โ”€ ai-analysis.json # AI output (JSON)
โ”œโ”€โ”€ ai-report.html # Human-friendly HTML dashboard
โ”œโ”€โ”€ ai-report.css # Dashboard styling
โ”‚
โ”œโ”€โ”€ generateTest.js # Converts stories โ†’ Playwright tests
โ”œโ”€โ”€ playwright.config.mjs # Config + JSON reporter
โ”œโ”€โ”€ package.json # NPM scripts for full automation
โ””โ”€โ”€ README.md # (this file)

โš™๏ธ Installation

git clone https://github.com/jtur671/playwright-ai-triage.git
cd playwright-ai-triage
npm install
npx playwright install
export OPENAI_API_KEY="your-key"

๐Ÿง  One-Command Workflow

Run this to:
Generate the test from your story
Run all Playwright tests
Analyze failures using AI
Build & open the HTML dashboard
npm run ai:flow

๐Ÿ‘‰ Individual Commands (Optional)

Generate tests from your stories

npm run ai:gen
Creates Playwright test files under tests/.

Run the Playwright test suite

npm run ai:test
Saves playwright-report.json.

Analyze failures using AI (JSON only)

npm run ai:analyze
Saves structured output in ai-analysis.json.

Build + open the HTML dashboard

npm run ai:report
Auto-opens ai-report.html in your browser.

๐Ÿค– How AI Analysis Works

After Playwright executes the tests, all failure metadata is passed to GPT-4.1:
Error message
Stack trace
Test title + project name
stdout/stderr logs
AI returns structured HTML with:

1. Plain-English Explanation

Why did this fail?

2. Probable Root Causes

2โ€“3 likely technical problems.

3. Suggested Test Fixes

Specific Playwright code improvements.

4. Flakiness Mitigation

Ways to reduce intermittent failures.

๐ŸŽจ HTML Dashboard Themes & Features

Dark-mode
Animated gradient highlight bars
Glowing hover transitions
Status badges
Collapsible AI analysis sections
External CSS for easy editing
Radial gradients & neon accent hues

๐Ÿงช Example AI Output (HTML)

<h3>Plain-English Explanation</h3>
<p>The success message never appeared...</p>

<h3>Probable Root Causes</h3>
<ul>
<li>Selector mismatch</li>
<li>API response delay</li>
<li>Redirect timing issue</li>
</ul>

<h3>Suggested Test Fixes</h3>
<ul>
<li>Use page.waitForURL('/dashboard')</li>
<li>Wait for stable locator instead of getByText</li>
</ul>

<h3>Flakiness Mitigation</h3>
<p>Increase timeout or add a network idle wait.</p>

๐Ÿ“ฆ Environment Variables

Set your OpenAI key using one of these methods:
Option 1: Export (recommended for quick setup)
export OPENAI_API_KEY="your-key"
Option 2: .env file (recommended for persistence)
# Copy the example file
cp .env.example .env

# Edit .env and add your key
OPENAI_API_KEY=your-key
Both methods work! If you use export, it takes precedence over the .env file.

๐Ÿงญ Roadmap & Enhancements

Multi-story batch generation
Test-to-story reverse engineering
Hit-map UI of frequent failures
CI pipeline integration
Slack/Teams bot that posts AI insights
Flaky test scoring over time

๐Ÿ’ฌ Contributing

Pull requests welcome!
Open issues for bugs, ideas, or UX/UI enhancements.

โญ Star the repo if you like it!

This project helps show how AI can supercharge real-world QA automation.
Let's build the future of testing. ๐Ÿ”ฅ
Like this project

Posted Dec 5, 2025

Developed an AI-driven test automation pipeline using Playwright and OpenAI.