Skip to content
AI Skills Central

Type to search Agent Skills, workflows, tutorials, tools and the glossary.

Tutorial

Exploratory testing with Playwright MCP

Give a coding agent a browser through Playwright MCP, run a time-boxed exploratory charter, record findings, and turn the confirmed ones into Playwright specs.

By Intermediate50 min hands-on
Bookmark

Bookmarks are kept in your free account, so you can find this page again on any device.

Sign in to bookmark
Quiz at the end
On this page

Exploratory testing is the part of testing where a person learns the product while testing it: trying odd inputs, following hunches, noticing what feels wrong. It has always been hard to automate because there is no script. A coding agent with a browser is a reasonable assistant for it. It can work through a flow quickly, try the boring variations you would skip, and write down what it saw. It is not a replacement for your judgement about what matters.

This tutorial connects Playwright MCP to a coding agent, runs a time-boxed exploratory session from a written charter, and converts confirmed findings into Playwright specs that run in CI. Checked against Playwright MCP 0.0.86 on 20 November 2026.

How Playwright MCP sees a page

Playwright MCP drives a real browser and gives the agent tools such as browser_navigate, browser_click, browser_type, browser_fill_form, browser_snapshot, browser_console_messages and browser_network_requests. Instead of screenshots, the agent works mainly from accessibility snapshots: a structured tree of roles, names and states, with a reference for each element. That makes its actions more reliable than pixel-guessing, and it has a useful side effect for testers. If an element has no accessible name, the agent struggles to find it, which is often a real accessibility bug.

1. Add the server

Pin the version so a session next month behaves like this one. For Claude Code:

claude mcp add playwright -- npx @playwright/mcp@0.0.86 --isolated --output-dir ./exploration

For Codex:

codex mcp add playwright -- npx @playwright/mcp@0.0.86 --isolated --output-dir ./exploration

For Cursor, add it to .cursor/mcp.json:

{
  "mcpServers": {
    "playwright": {
      "command": "npx",
      "args": ["@playwright/mcp@0.0.86", "--isolated", "--output-dir", "./exploration"]
    }
  }
}

The flags:

  • --isolated keeps the browser profile in memory, so every session starts logged out with no cookies from the last one. You want that for testing.
  • --output-dir collects screenshots and other files the agent saves.
  • The browser is headed by default, so you can watch. Add --headless on a machine without a display.

Optional: --caps=testing adds assertion tools (browser_verify_text_visible, browser_verify_element_visible and others) and browser_generate_locator, which help in step 4.

Check it loaded: /mcp in Claude Code or Codex should list playwright with its tools. Connect MCP servers covers troubleshooting.

2. Write a charter

A charter is the classic exploratory-testing brief: what to explore, with what resources, to discover what. It keeps the session focused and gives you something to judge the results against. Save it as exploration/charter.md:

# Charter: discount codes at checkout

Explore: applying, removing and combining discount codes in the checkout
With: test account shopper1@example.test / see 1Password "staging shopper"
      codes SAVE10 (10%, min 50), FREESHIP (free delivery), EXPIRED2025 (expired)
To discover: incorrect totals, confusing messages, states the user cannot
             get out of, and accessibility problems in the discount UI.

Environment: https://staging.shop.example.test
Time box: 30 minutes of browser actions.

Rules:
- Do not complete a real payment. Stop at the payment step.
- Record every finding in exploration/findings.md as you go, using the template.
- A finding needs: steps to reproduce, expected, actual, a screenshot name,
  and your confidence that it is a bug (high/medium/low).
- Also note things that worked as expected, briefly, so we know what was covered.

Keep credentials out of the charter file itself if it goes into Git; tell the agent where they are or type them in the session.

3. Run the session

Give the agent the charter and a findings template:

Read exploration/charter.md and follow it using the Playwright browser tools.

Create exploration/findings.md with this structure:
## Findings
### F1: <short title>
- Steps:
- Expected:
- Actual:
- Evidence: <screenshot file>, console errors if any
- Confidence: high | medium | low
## Covered and fine
- <one line per area that behaved correctly>

Vary inputs the way a curious tester would: lower/upper case codes, spaces,
applying the same code twice, removing a code after changing quantity,
going back and forward between steps, and keyboard-only use.
Check the browser console and failed network requests after each step.

Watch the browser while it works. You will learn things about your app from the agent’s struggles: unlabelled buttons, focus traps, error messages that do not say which field is wrong.

When it finishes, open findings.md. A typical session produces a mix of real bugs, misunderstandings of the intended behaviour and noise. Triage each one yourself:

  • Reproduce it by hand. If you cannot, mark it and move on.
  • Check it against the requirement, not against the agent’s expectation. Agents confidently invent rules.
  • Keep the confirmed ones and file them as you would any bug.

4. Turn findings into specs

A confirmed bug should become a regression test, so it stays fixed. Ask the agent to write one Playwright test per confirmed finding, using what it learned about the page:

For findings F1 and F3 (confirmed), write Playwright tests in
tests/checkout/discounts.spec.ts.

Rules:
- Use role-based locators (getByRole, getByLabel) taken from the page
  snapshot, not CSS selectors. Use browser_generate_locator if unsure.
- One test per finding, named after the expected behaviour.
- Assert on what the user sees (totals, messages), not on internal state.
- Reuse the login helper in tests/helpers/auth.ts.
- Run the tests with npx playwright test tests/checkout/discounts.spec.ts
  and show me the output. They should fail until the bugs are fixed.

A resulting test might look like this:

import { test, expect } from "@playwright/test";
import { loginAsShopper } from "../helpers/auth";

test("applying the same discount code twice does not double the discount", async ({ page }) => {
  await loginAsShopper(page);
  await page.goto("/checkout");

  const code = page.getByLabel("Discount code");
  const apply = page.getByRole("button", { name: "Apply" });

  await code.fill("SAVE10");
  await apply.click();
  await expect(page.getByText("SAVE10 applied")).toBeVisible();
  const totalAfterFirst = await page.getByTestId("order-total").textContent();

  await code.fill("SAVE10");
  await apply.click();

  await expect(page.getByText("This code is already applied")).toBeVisible();
  await expect(page.getByTestId("order-total")).toHaveText(totalAfterFirst ?? "");
});

Review these like any test written by someone new to the team:

  • Does it fail for the right reason before the fix, and pass after?
  • Would it still pass if the bug came back in a slightly different form? Weak assertions (“some text is visible”) are the usual problem.
  • Are the locators stable? Role and label locators survive redesigns; text that marketing rewrites does not.

5. Make it repeatable

Exploratory sessions are worth running regularly, not once:

  • Keep charters in the repository and rerun them after major changes to an area.
  • Save each session’s findings.md with the date, so you can see what changed.
  • When the planner, generator and healer agents fit better (scripted coverage of known flows), use Playwright test agents instead. Exploration finds the unknowns; the test agents systematise the knowns.

MCP or CLI?

Playwright’s own README notes that for coding agents, a CLI driven through a skill is often more token-efficient than MCP, because it avoids loading large tool schemas and full accessibility trees into context. The playwright-cli skill takes that route. MCP is still the more convenient choice for interactive exploration, where you want rich page state and to watch the browser; for long automated runs, try both and compare token use.

Pitfalls

Exploring without a charter. You get a long transcript of clicks and no conclusions.

Trusting the agent’s verdicts. “Bug: discount should apply to delivery” may simply be wrong about your rules. You decide what is a bug.

Testing against production. Agents fill forms and press submit. Use test data.

Keeping every generated test. Only confirmed, valuable findings become specs. A suite full of agent-written trivia slows CI and gets ignored.

Next steps

Covers

Check your understanding

Exploratory testing with Playwright MCP quiz

Connecting Playwright MCP, writing a charter, triaging agent findings and turning confirmed bugs into Playwright specs.

7 questions · pass mark 70%

Question 1 of 70 answered
  1. Why pin the Playwright MCP version when adding the server?
Back to top