AI Test Agent
🚀 AI-Powered Automation Testing

Build an AI Agent
for Website Automation Testing

A complete guide to building an autonomous website testing agent using Playwright, Ollama, local LLMs, browser automation and intelligent failure analysis.

01 AI Planner
02 Browser Agent
03 Test Executor
04 AI Analyzer

What are we building?

The goal is to create an AI agent that can open a website, understand its UI, create test scenarios, interact with the browser, detect failures and explain the failures automatically.

🧠

AI Brain

The LLM understands requirements, creates test cases, decides the next action and analyzes failures.

🖥️

Browser Hands

Playwright controls Chromium, Firefox or WebKit and performs real browser interactions.

📊

Test Reporter

Collect screenshots, console errors, network failures, test results and AI-generated explanations.

AI Testing Agent Architecture

A good architecture separates the AI reasoning layer from the browser execution layer.

👤 User "Test my website"
🧠 AI Planner Generate test scenarios
🤖 AI Agent Select tools & actions
🌐 Playwright Control browser
🔍 Observe Results DOM / Console / Network
📊 AI Analyzer Find root cause
📋 Test Report PASS / FAIL / Issues

Recommended Tech Stack

Component Technology Purpose
Browser Automation Playwright Control browser and execute tests
AI Runtime Ollama Run local AI models
LLM Gemma / Qwen Reasoning and test generation
Backend Node.js Agent application
Language TypeScript Application development
Database SQLite Store tests and results
Frontend React Testing dashboard

Step 1 — Create the Project

Create a Node.js project and install Playwright.

Terminal
mkdir ai-web-tester
cd ai-web-tester

npm init -y

npm init playwright@latest

npx playwright install
💡 Tip Use TypeScript if you plan to build a production-grade agent. It provides better type safety for agent tools and actions.

Step 2 — Use Playwright

Playwright is the browser automation layer of your AI agent. It performs the actual actions that the AI decides.

Open websites
Click buttons
Fill forms
Select dropdowns
Take screenshots
Detect console errors
Monitor network failures
Validate page content
browser.ts
import { chromium } from "playwright";

const browser = await chromium.launch({
    headless: false
});

const page = await browser.newPage();

await page.goto("https://example.com");

console.log(await page.title());

await page.screenshot({
    path: "homepage.png",
    fullPage: true
});

await browser.close();

Step 3 — Add a Free Local AI

Ollama allows you to run an LLM locally on your computer. This is useful when you want to develop without depending on paid API requests.

1 Install Ollama

Install Ollama on your computer.

2 Download Model

Download a supported local model.

3 Run Model

Start the model through Ollama.

Terminal
ollama pull gemma3

ollama run gemma3
Local AI Architecture
Your Agent Ollama Local LLM Response

Step 4 — Build the AI Agent

The AI agent should not directly execute arbitrary code. Instead, give the model a controlled set of tools.

01 Understand Understand user requirement
02 Plan Create test scenarios
03 Act Call browser tools
04 Observe Read browser results
05 Reason Decide next action
06 Report Generate final result

Example User Request

👤

Test the login functionality of https://mywebsite.com. Check both valid and invalid credentials.

Give the Agent Browser Tools

Tools are the bridge between the AI model and Playwright.

open_page(url) Open webpage
get_elements() Inspect UI
click(target) Click element
type(target, text) Fill input
select(target, value) Select option
screenshot() Capture screen
get_console_errors() Read JS errors
get_network_errors() Read failed requests

Tool Action Example

agent-action.json
{
  "action": "click",
  "target": "Login"
}
⚠️ Important Security Rule

Never allow an LLM to execute arbitrary JavaScript or shell commands directly. Validate every action through your own application layer before Playwright executes it.

Complete Testing Workflow

01

User Input

User provides website URL and testing requirements.

02

AI Discovery

Agent opens the website and identifies pages, forms, buttons and important UI elements.

03

Test Generation

LLM creates structured test cases from the requirements and discovered UI.

04

Browser Execution

Playwright executes each action and assertion.

05

Observation

Collect DOM state, screenshots, console messages, network failures and HTTP responses.

06

AI Analysis

The AI analyzes failed tests and determines possible root causes.

07

Report

Generate PASS/FAIL results and an explanation for every failure.

AI Failure & Root Cause Analysis

A major advantage of an AI testing agent is that it can explain why a test failed rather than simply saying "FAIL".

❌ Test Failure
Test: Login

Expected:
Dashboard should appear

Actual:
User remained on login page

Console:
TypeError: Cannot read properties of undefined

Network:
POST /api/login → 500
🧠 AI Analysis
Root Cause:
Login API returned HTTP 500.

Severity:
Critical

Likely Issue:
Backend authentication service failure.

Recommendation:
Inspect /api/login server logs.

Capture Browser Errors

monitor.ts
page.on("console", msg => {

    if (msg.type() === "error") {
        console.log(
            "Console Error:",
            msg.text()
        );
    }

});

page.on("requestfailed", request => {

    console.log(
        "Request Failed:",
        request.url(),
        request.failure()?.errorText
    );

});

Playwright MCP

For a more advanced agent architecture, you can use Playwright MCP to provide browser interaction capabilities to an AI agent.

🧠 AI Model
🔌 MCP
🎭 Playwright
🌐 Browser
Terminal
npx @playwright/mcp@latest

Recommended Project Structure

ai-web-tester/
│
├── agent/
│   ├── agent.ts
│   ├── planner.ts
│   ├── executor.ts
│   └── analyzer.ts
│
├── browser/
│   ├── browser.ts
│   └── actions.ts
│
├── tests/
│   └── generated/
│
├── screenshots/
│
├── reports/
│
├── database/
│   └── sqlite.db
│
├── frontend/
│   └── dashboard/
│
├── playwright.config.ts
├── package.json
└── README.md

Generated Playwright Test

login.spec.ts
import { test, expect } from "@playwright/test";

test("valid login", async ({ page }) => {

    await page.goto(
        "https://example.com/login"
    );

    await page
        .getByLabel("Email")
        .fill("test@example.com");

    await page
        .getByLabel("Password")
        .fill("password");

    await page
        .getByRole("button", {
            name: "Sign in"
        })
        .click();

    await expect(
        page.getByText("Dashboard")
    ).toBeVisible();

});

Testing Dashboard

AI Website Tester
Total Tests 47
Passed 42
Failed 5
Critical 1
FAIL Login API returns 500 Critical
FAIL Checkout button not working High
PASS Product search Completed

Build It in Phases

01
Browser Automation

Build Playwright browser controls.

02
AI Integration

Connect Ollama and a local LLM.

03
Agent Tools

Add click, type, inspect and screenshot tools.

04
Autonomous Agent

Implement plan → act → observe → reason loop.

05
AI Failure Analysis

Analyze screenshots, console and network errors.

06
Dashboard

Create a UI for running and monitoring tests.

07
CI/CD

Run the AI tester automatically in CI pipelines.

Your Complete AI Testing Agent

👤
User
🧠
LLM
🤖
Agent
🛠️
Tools
🎭
Playwright
🌐
Browser
📊
Report

Start with a small MVP: Playwright + Ollama + a handful of browser tools. Once that works reliably, add autonomous planning, failure analysis, persistent test history and a dashboard.

Start Building ↑