What a Selenium AI Agent Is
Why This Matters
Ask a general chatbot to “write Selenium tests for my shop” and you get code for a shop it has never seen: invented selectors, invented texts, time.sleep(3) everywhere. It compiles; it does not test anything. A test agent is different: it opens your application in a real browser, looks at what is there, and checks its own work against the page. This lesson explains how that works, and where you stay in charge.
What you will learn
- What Playwright’s test agents (planner, generator, healer) are, and how Selenium AI Agent brings them to Selenium
- How an AI assistant drives a browser through an MCP server: tools, page snapshots and element refs
- Which decisions the AI makes, and which ones stay with you
From Playwright’s agents to Selenium
In October 2025 Playwright 1.56 introduced three test agents:
| Agent | Does | Produces |
|---|---|---|
| Planner | Explores the application in a browser and decides what to test | A Markdown test plan |
| Generator | Turns the plan into test code, checking every step in the browser | Test files |
| Healer | Runs the tests and repairs the ones that fail | Fixed tests, or a report of a real bug |
The idea is strong: the AI does not guess, it observes. But it only works for Playwright. Many teams have years of Selenium tests in Python, Java or C#, and they are not going to rewrite them.
Selenium AI Agent (selenium-ai-agent on npm, open source, MIT licence) brings the same three agents to Selenium, plus two more:
- a migrator that upgrades existing Selenium 3 tests to Selenium 4, one file at a time, proving each still passes
- a regression analyzer that builds a risk profile to decide what to test first
It generates Python with pytest by default, and Java (JUnit 5 or TestNG), C#, JavaScript/TypeScript, WebdriverIO and Robot Framework on request.
How an AI drives a browser: MCP
The agents are not a separate program with their own AI. They are instructions and tools for the AI assistant you already use: Claude Code, GitHub Copilot in VS Code, Cursor, or the AI assistants in JetBrains IDEs.
The connection is the Model Context Protocol (MCP). Selenium AI Agent is an MCP server: a small Node.js program that starts a Selenium browser and offers the assistant about 65 tools (79 with Selenium Grid): navigate_to, click_element, capture_page, planner_save_plan, healer_fix_test and so on.
you ──prompt──> AI assistant ──tool call──> Selenium AI Agent ──WebDriver──> Chrome
(Claude Code, <──result─── (MCP server) <─────────── your app
Copilot, …)
The loop is always the same:
- The assistant calls a tool, for example
navigate_towith a URL. - The server does it in the browser and returns what happened, usually with a snapshot of the page.
- The assistant reads the snapshot and decides the next tool call.
A snapshot is not a screenshot. It is the page’s accessibility tree as text: every heading, button, link and field, with its role, its name and a ref:
- textbox "Search for items" [ref=e16, css=input[data-testid="search-input"]]
- button "shopping_cart0 items$0.00" [ref=e13, css=button[data-testid="cart-button"]]
The assistant clicks by ref (click_element with ref: "e13"), and the server already worked out a stable CSS or XPath selector for every element, test ids first. That is why the generated tests use selectors that exist, instead of invented ones.
Where you decide
An agent that can click anything and write any file needs boundaries. Selenium AI Agent builds them in, and this course is largely about using them:
| Decision | Who | How |
|---|---|---|
| What to test | You, helped by the planner | The planner writes a plan; you approve it in a review page. The generator refuses a plan nobody approved. |
| How to automate it | The generator | Selectors checked live; Selenium’s own rules for AI agents enforced (no sleeps, no Selenium 3 APIs). |
| Whether a fix is acceptable | You, by policy | A determinism profile decides what the healer may change alone: anything, everything except assertions, or locators and waits only. |
| Whether a test is trustworthy | A check without AI | verify_test_stability runs each test repeatedly and with changed expected values that must make it fail. |
| Whether the suite may merge | A CI gate without AI | selenium-ai-agent gate --run fails the build for unapproved plans, edited tests or unverified tests. |
Lesson 4 goes through every one of these guardrails. The pattern is the one from the Agentic Engineering course: the AI makes code cheap; trust has to be built separately, with checks that do not depend on the AI.
Exercise
Watch the two short demos in the project README: the planner (2 minutes) and the generator (2 minutes). For each, write down: which tools were called, what the AI decided by itself, and where a person had to look or approve.
Show suggested answer
- Planner demo:
planner_setup_pageopens the shop,planner_explore_pagelists the elements per page, and the AI decides which flows are worth testing (cart, checkout) and how to group them.planner_save_planwritesspecs/shopping-cart-and-checkout.md: 2 suites, 8 tests. A person decides whether this is the right set of tests, by reviewing the plan. - Generator demo:
generator_setup_pagestarts a recording, the AI performs each plan step in the browser, andgenerator_write_testsaves one pytest file per plan test, after checking the selectors against the live page. Running the suite finds a real bug. A person looks at the report and decides whether a failure is a bug in the shop or in the test.
The AI does the exploring, the writing and the checking against the page. People decide what is worth testing and what a failure means.
Exam-style questions
1. What does the MCP server of Selenium AI Agent provide to an AI assistant?
- A. Its own large language model
- B. Tools to drive a Selenium browser and work with test plans and tests, which the assistant calls
- C. A cloud service that runs tests
- D. A replacement for Selenium WebDriver
Show answer
2. Why do tests from a test agent usually have working selectors, where tests from a general chatbot often do not?
- A. The agent uses a better language model
- B. The agent reads the real page through snapshots with refs and checks selectors against the live page before saving
- C. The agent only uses XPath
- D. The agent copies selectors from the developers’ code
Show answer
3. Which decision stays with a person in the intended workflow?
- A. Which CSS selector to use for each element
- B. Approving the test plan before tests are generated
- C. Which tool to call next
- D. How to format the test file