The Testing Academy · Masterclass

Playwright MCP + AI Agents.

Stop hand-writing locators and start describing what you want. The Playwright MCP server exposes a real browser as a set of tools over the Model Context Protocol, so an AI agent can read the page, click, type, and assert in plain language - then hand you a durable @playwright/test spec. This session takes you from "what is MCP" to an agent driving the live TTACart store end to end.

Host
Pramod Dutta
Track
Playwright + MCP
Audience
QA / SDET
App under test
TTACart

The 30-minute pitch

Four things you walk away able to do today.

Understand

Grasp the Model Context Protocol

Know what MCP is, how a client and a tool server talk over stdio or HTTP, and why it lets any LLM call the same browser tools.

Run

Start the Playwright MCP server

Launch npx @playwright/mcp@latest, see it expose a real browser, and confirm the tools appear in your client.

Drive

Control TTACart with tools

Snapshot the page, click, type, and assert - using accessibility snapshots, not pixel guesses - to log in and check out.

Automate

Wire it into an AI agent

Let an agent perceive, decide, act, and re-snapshot in a loop, with you reviewing - then turn the run into a committed spec.

App under test

We explore TTACart

Every example on this page points the agent at the same live demo store, so you can copy a prompt and watch the browser move. It has a login, an inventory grid, item details, a cart, and a multi-step checkout - enough surface for an agent to perceive and act on.

Live

TTACart store

A small e-commerce app with login, inventory, cart, and checkout. Point the MCP browser at it and let the agent explore.

https://app.thetestingacademy.com/playwright/ttacart/

Flow

Login → cart → checkout

The canonical journey. Use the credentials shown on the TTACart login screen - never hard-code secrets into prompts or specs.

Why MCP

Rich, stable structure

Elements carry roles and test ids, so the accessibility snapshot the agent reads is clean - it picks the right element without brittle guessing.

The protocol

What is the Model Context Protocol?

MCP is an open standard for connecting AI applications to external tools and data. Instead of every model inventing its own plugin format, MCP defines one contract: an AI app (the host, with an MCP client) connects to an MCP server that advertises a list of tools. The model picks a tool, the client sends the call, the server runs it and returns the result.

Client

The AI app

Claude Code, Cursor, VS Code, or your own agent. It holds the LLM and an MCP client that discovers and invokes tools.

Server

The tools

A process that advertises tools (here, a browser). It runs each call and returns structured results back to the client.

Transport

stdio or HTTP

The client talks to the server over standard input/output for a local process, or over HTTP for a remote one.

Why it matters: because the contract is standard, the same Playwright MCP server works in any MCP-aware client. Learn the tools once and reuse them everywhere - no bespoke glue per assistant.

The server

The Playwright MCP server

Playwright MCP is an official Microsoft server that exposes a real, automated browser as MCP tools. One command starts it - no spec file, no boilerplate:

terminal · run the server
# start the Playwright MCP server (latest)
npx @playwright/mcp@latest

# headless for CI or background runs
npx @playwright/mcp@latest --headless

# fresh, throwaway profile each run
npx @playwright/mcp@latest --isolated

# expose over HTTP instead of stdio
npx @playwright/mcp@latest --port 8931
A11y-driven

Snapshots, not pixels

The agent acts on Playwright's accessibility snapshot of the page - structured roles and names - so it never has to guess from a screenshot.

Deterministic

Fast and reliable

Tool calls map to Playwright actions with built-in auto-waiting, so steps are stable and quick - no vision model in the hot path.

Real browser

The agent can see and act

A genuine Chromium (or Firefox/WebKit) the agent navigates, reads, and drives - the same engine your tests run on.

Setup

Add Playwright MCP to your client

MCP clients read a JSON config that lists each server by a name, a command to launch, and its args. The block below is the standard Playwright MCP entry - it works in Claude Code, Cursor, and VS Code (the file location differs per client, the entry does not).

config · mcpServers entry
{
  "mcpServers": {
    "playwright": {
      "command": "npx",
      "args": ["@playwright/mcp@latest"]
    }
  }
}
FlagAdd to args when you want…
--headlessNo visible window (CI, background, or servers without a display).
--isolatedA clean, in-memory profile per session - no cookies persisted to disk.
--browser chromePick the engine: chrome, firefox, webkit, or msedge.
--port 8931Serve over HTTP for a remote or shared agent instead of stdio.
Verify: after adding the entry, restart the client and open its tools/MCP panel. You should see the browser_* tools listed. If they are missing, check Node 18+ and that npx can reach the package.

The toolbox

The key browser tools

These are the tools the agent calls. You rarely name them by hand - you describe the goal and the model chooses - but knowing them helps you read and trust what the agent does.

ToolWhat it does
browser_navigateLoad a URL in the current page.
browser_snapshotCapture the accessibility tree - the structured view the agent reads.
browser_clickClick a target element from the snapshot.
browser_typeType text into an editable field.
browser_fill_formFill several form fields in one call.
browser_select_optionChoose an option from a dropdown.
browser_take_screenshotCapture a visual image of the viewport or an element.
browser_wait_forWait until text appears or disappears, or for a time.
browser_network_requestsList the network calls made since the page loaded.
browser_console_messagesRead console output and errors from the page.
browser_tabsList, open, close, or switch between tabs.
browser_evaluateRun custom JavaScript on the page or an element.
Read the snapshot first: the agent always calls browser_snapshot before acting. Each element in that snapshot has a stable reference the next tool call targets - that is why MCP clicks the right thing without a screenshot.

Hands-on

Drive TTACart with natural language

With the server connected, you talk to the agent in plain English. It translates each instruction into browser_* calls and reports back the snapshot it acted on. Here is a full login-to-checkout exploration.

agent · navigate and read the page
You:  Open https://app.thetestingacademy.com/playwright/ttacart/
      and snapshot the page.

Agent: browser_navigate -> https://app.thetestingacademy.com/playwright/ttacart/
       browser_snapshot
       -> heading "Login", textbox "Username",
          textbox "Password", button "Login",
          plus the on-screen credentials hint.
agent · log in with the on-screen credentials
You:  Log in using the username and password shown
      on the login screen, then snapshot the result.

Agent: browser_type  -> textbox "Username"  (from the hint)
       browser_type  -> textbox "Password"  (from the hint)
       browser_click -> button "Login"
       browser_snapshot
       -> heading "Products", a grid of items,
          each with an "Add to cart" button.
agent · add to cart and check out
You:  Add the first product to the cart, go to the cart,
      and complete checkout with sample details.

Agent: browser_click  -> "Add to cart" (first item)
       browser_click  -> cart link
       browser_click  -> "Checkout"
       browser_fill_form -> first name, last name, postal code
       browser_click  -> "Continue" then "Finish"
       browser_snapshot
       -> heading "Thank you for your order!"
Credential-safe: tell the agent to read the credentials displayed on the TTACart login screen. Do not paste a username or password into the prompt - keep secrets out of your chat history and out of any generated spec.

How agents work

The agent loop: perceive, decide, act

An AI agent does not run a script. It runs a loop: read the current state, decide the next step, call one tool, then look again. MCP is what makes each "act" possible and each "perceive" trustworthy.

1

Perceive

Call browser_snapshot to read the page as a structured accessibility tree.

2

Decide

The model picks the next action and the element to target from that snapshot.

3

Act

It calls one tool - browser_click, browser_type, browser_navigate.

4

Re-snapshot & assert

Snapshot again, confirm the expected text appeared, and repeat or stop.

Human in the loop: keep a person reviewing each step on real apps. Approve destructive actions (submit, pay, delete) before they run, and watch the snapshots the agent reports.
Guardrails: point the agent at the demo store, not production. Run --isolated so state does not leak between sessions, and never give it real credentials.

From exploration to a test

Turn the run into a Playwright spec

An MCP exploration is repeatable but not durable - it lives in a chat. The payoff is asking the agent to emit a real @playwright/test file from what it just did, so the journey becomes a committed test you run in CI.

agent · ask for a durable spec
You:  Generate a Playwright Test (TypeScript) spec for the
      login-to-checkout flow you just ran on TTACart.
      Use role and label locators, read the credentials
      on the login screen, and assert the success heading.

Agent: -> writes tests/ttacart-checkout.spec.ts
       using getByRole / getByLabel locators and
       expect(...).toHaveText("Thank you for your order!")
terminal · review, then run it like any test
# run the agent-generated spec headed to watch it
npx playwright test tests/ttacart-checkout.spec.ts --headed

# open the trace if anything fails
npx playwright show-trace test-results/.../trace.zip
Always review generated code. Check the locators are stable (roles, labels, test ids - not nth-child), confirm there are no hard-coded secrets, run it once, then commit. The agent drafts; you own the test.

Reference

The Playwright MCP cheat sheet

ItemValue
Run the servernpx @playwright/mcp@latest
Headlessnpx @playwright/mcp@latest --headless
Isolated profilenpx @playwright/mcp@latest --isolated
HTTP transportnpx @playwright/mcp@latest --port 8931
Client config keymcpServers.playwright.command = npx
Client config args["@playwright/mcp@latest"]
Read the pagebrowser_snapshot
Go to a URLbrowser_navigate
Click / typebrowser_click · browser_type
Fill a formbrowser_fill_form
Pick a dropdown optionbrowser_select_option
Screenshotbrowser_take_screenshot
Wait for textbrowser_wait_for
Network / consolebrowser_network_requests · browser_console_messages
Tabs / JSbrowser_tabs · browser_evaluate

Hands-on

Six MCP drills on TTACart

A

Connect the server

Add the mcpServers entry, restart your client, and confirm the browser_* tools appear.

B

Snapshot the store

Ask the agent to open TTACart and run browser_snapshot; read the roles and names it returns.

C

Agent logs in

Have it log in using the credentials shown on the login screen, then snapshot the products page.

D

Complete checkout

Add an item, go to the cart, and finish checkout; assert the success heading via a snapshot.

E

Capture a screenshot

Use browser_take_screenshot to grab the order-confirmation page as evidence.

F

Emit a spec

Ask the agent to generate a @playwright/test file from the run, review the locators, and commit it.

Sources

Official references

ReferenceURL
Playwright MCP docshttps://playwright.dev/docs/mcp
Playwright MCP on GitHubhttps://github.com/microsoft/playwright-mcp
Model Context Protocolhttps://modelcontextprotocol.io
Playwright Test docshttps://playwright.dev/docs/intro
TTACart demo apphttps://app.thetestingacademy.com/playwright/ttacart/
Class dismissed. You can now run the Playwright MCP server, drive a real browser with natural language over the Model Context Protocol, understand the agent loop, and turn an exploration into a committed Playwright test - all on a real app. Next session: running an agent suite in CI with guardrails.