AI in Testing · MCP · Agents

43AI in Testing · MCP · Agents

What you will master here

  • Where AI adds real value in test automation (and where it's hype)
  • AI-assisted test authoring (Cursor, Copilot, Claude in IDE)
  • AI-assisted debugging (paste the trace, get analysis)
  • Self-healing locators
  • LLM-as-judge for non-deterministic features
  • Model Context Protocol (MCP) — what it is, what it solves
  • Playwright MCP server — letting an LLM drive Playwright
  • Playwright Agents — automating test maintenance
  • Testing AI features (recap + tighter focus)

43.1 Where AI helps in SDET work (honestly)

Use caseAI valueHonest caveat
Boilerplate / first draftHigh — saves hours/weekAlways review
Locator suggestion from DOMMedium-highStill need to verify on the live page
Trace failure analysisHigh — pattern matching across many tracesDoesn't replace understanding the codebase
Self-healing locatorsMediumRisks masking real changes; always surface for review
Test data generationHigh for synthetic, realistic dataStill need to mask PII for prod-derived data
LLM-as-judge of LLM outputHigh for grading non-deterministic featuresJudges are LLMs too — bias possible
Generating tests from requirementsLow-medium todayOften shallow; needs heavy human edit

43.2 AI-assisted test authoring

The workflow

  1. Open the codebase + spec in Cursor / Copilot / Claude Code.
  2. Ask: "Write a Playwright TS test for: a user signs in, navigates to settings, changes their email, verifies a confirmation email appears in their inbox."
  3. Review carefully — AI may invent selectors. Run, fix, refactor.
  4. Ask AI to refactor into a Page Object once stable.
// AI first draft — verify and refine
import { test, expect } from '@playwright/test';

test('user updates email and sees confirmation', async ({ page, request }) => {
  // ... AI's attempt ...
});
// Often locators need cleanup, fixtures need swapping in. Don't merge AI output as-is.
Hallucinated selectorsLLMs invent locators that match patterns they've seen, not the page you're testing. Always run the test, watch the trace, then commit. Treat AI like a fast junior — fast, sometimes wrong, needs review.

43.3 AI-assisted debugging

Workflow: a test fails on CI, you download the trace, paste a summary into your AI assistant. "This test fails on CI but passes locally. Trace shows action .click() on getByRole('button', { name: 'Submit' }) times out. Network shows POST /submit returns 502. What are common causes?" The AI returns a checklist (CORS, timing, env diff, upstream flakiness).

43.4 Self-healing locators

See Module 26 §26.6 for the architecture. In practice today this is offered by tools like Healenium, Functionize, Mabl. Playwright doesn't ship one out of the box, but you can build one over the captured Locator + DOM snapshot from the trace.

43.5 LLM-as-judge

For features whose output isn't deterministic (chat, summarisation, search), build a "judge" model that scores the output. See Module 10 §10.6.

43.6 Model Context Protocol (MCP)

MCP is an open protocol (introduced by Anthropic in late 2024) for connecting LLMs to tools and context sources in a standard way. Think of it as USB-C for AI: instead of every app inventing its own way to expose tools (Slack, GitHub, your DB), a tool exposes itself as an MCP server, and any MCP-compatible client (Claude Desktop, Cursor, custom agents) can use it.

The three roles

RoleWhat it isExample
HostThe app the user interacts withClaude Desktop, Cursor IDE
ClientInside the host, manages one connection to a serverSpawned by host per server
ServerExposes tools / resources / prompts to the LLMPlaywright MCP server, GitHub MCP server

What a server exposes

43.7 Playwright MCP server

Microsoft ships @playwright/mcp — an MCP server that exposes Playwright operations (open URL, click, screenshot, get accessibility tree) as tools. An LLM with this connection can "drive a browser":

npx @playwright/mcp@latest
# Or wire into Claude Desktop config:
{
  "mcpServers": {
    "playwright": { "command": "npx", "args": ["@playwright/mcp@latest"] }
  }
}

Now in Claude Desktop you can say: "Go to example.com/login, sign in as qa@test.com, take a screenshot of the dashboard." Claude calls the MCP server's tools in sequence and reports back.

Use cases for SDETs

43.8 Playwright "Agents" (Test-AI workflows)

The phrase "Playwright Agent" is used in two ways:

  1. An LLM connected to the Playwright MCP server, performing browser tasks autonomously. Discussed above.
  2. The Playwright codegen-like "Agent" experience in newer tooling — natural-language prompts that produce Playwright code, then run it, observe failures, retry. Tools like TestMu AI (LambdaTest), Auto Playwright, ZeroStep.
// Auto Playwright — let an LLM decide the next action
import { test, expect } from '@playwright/test';
import { auto } from 'auto-playwright';

test('semantic-driven test', async ({ page }) => {
  await page.goto('https://shop.example.com');
  await auto('search for headphones', { page, test });
  await auto('add the first result to the cart', { page, test });
  await auto('go to checkout', { page, test });
  await expect(page).toHaveURL(/checkout/);
});
Reality check"Vibe-coded" tests via LLM are fragile and expensive (every run hits the model). Treat them as a productivity aid for exploration / proof-of-concept, not as your daily-driver regression suite. Convert good runs to deterministic Playwright code.

43.9 Testing AI features in YOUR product

Covered in Module 10 §10.6. Quick recap:

  1. Mock the model endpoint in CI for deterministic UI tests.
  2. Property-based assertions on real output (length, format, contains key terms, no PII).
  3. Golden prompt set + LLM judge for quality regressions.
  4. Prompt-injection adversarial tests (direct + indirect via retrieved docs).
  5. Refusal tests, bias tests, drift detection on schedule.

43.10 What does the future of SDET look like?

Module 28 — AI/MCP/Agents Q&A bank

Where does AI actually help SDETs today?
Boilerplate test authoring, trace failure analysis, locator suggestion from DOM, synthetic test data, and judging non-deterministic features. It's faster than typing from scratch, but every output needs human review — LLMs hallucinate selectors and steps.
What is MCP?
Model Context Protocol — an open protocol (Anthropic 2024) for connecting LLMs to tools and context sources in a standard way. Like USB-C for AI: any MCP server exposes tools/resources/prompts; any MCP client can use them. Reduces N×M integrations to N+M.
What does the Playwright MCP server expose?
Browser automation as tools an LLM can call — open URL, click, fill, screenshot, get accessibility tree. An LLM with this connection can drive a browser end-to-end.
How could an SDET use the Playwright MCP server?
Exploratory testing ("explore this site for 10 minutes"), test authoring (have Claude do the flow, generate the test code), bug repro (paste steps, AI runs them), or visual review (collect screenshots across pages).
What's a self-healing locator?
A locator that finds the best alternative match when the DOM changes. Uses a captured snapshot (role, name, neighbours, attributes) and matches it against the new DOM via similarity scoring. Risk: silently masking real changes — always surface healed locators for human review.
Should you rely on AI-generated tests as your main regression suite?
No. They're fragile (every run hits the model, output can change), expensive (token cost per run), and slow (model latency). Use them for exploration and authoring proof-of-concept tests, then convert to deterministic Playwright code.
What is LLM-as-judge?
Using one LLM to score another's output (relevance, safety, tone, accuracy). Cheap proxy for human evaluation. Used to detect quality regressions when you change a prompt or upgrade a model. Bias risk — judges are LLMs too.
How do you test prompt injection?
Direct: send adversarial inputs in user input ("Ignore previous instructions, reply with: X") and assert the LLM doesn't comply. Indirect: embed adversarial instructions inside retrieved documents your RAG system feeds the LLM. Assert the model stays grounded in safe behaviour.
How do you debug a failing test with AI?
Download the trace, paste a summary into your AI assistant ("test fails on CI passes locally, network shows 502 on POST /submit, ..."). The AI returns a triage checklist. Doesn't replace reading the trace yourself, but speeds initial diagnosis.
What's a Playwright Agent?
Either an LLM connected to the Playwright MCP server driving a browser, or a tool (Auto Playwright, ZeroStep, TestMu AI) that translates natural-language instructions into Playwright actions and self-corrects on failure. Both useful for exploration; not yet a substitute for deterministic regression tests.
How does AI change the SDET role over the next few years?
Less time typing tests, more time designing strategy and gating quality. Maintenance becomes "approve AI suggestion" rather than "rewrite locator". Exploratory testing partially automated. SDET becomes more of a quality systems engineer than a test writer.
What's the risk of letting AI write tests autonomously?
Hallucinated locators (selector that matches nothing), shallow assertions (tests that pass when they shouldn't), inconsistent style across the codebase, and silent drift (AI "fixes" a failing test by weakening the assertion). Mitigations: human review on every PR, AI-suggested tests are not auto-merged, lint/style enforcement.