AI-assisted testing

Playwright MCP: how AI works with a real application

Playwright MCP lets an AI assistant work with a browser and inspect an application in a particular state. A test draft can then use more than a written description. The assistant can find the actual form, perform permitted steps and inspect the result. It still needs to know what the application should do.

MCP stands for Model Context Protocol. It connects external tools to an AI client that supports the protocol. Playwright MCP exposes browser control through Playwright. The official guide explains its role and basic setup.

What changes compared with a description-only draft

A model asked only to write a sign-in test may not know the field labels or whether the form appears on a separate page or in a dialogue. It may invent a selector or find another element with similar text.

MCP can provide a structured page snapshot with roles, names and element references. The model can distinguish an email field from search, for example, and inspect whether an error message appears after a click. A screenshot adds visual context, but the image alone does not explain every programmatic relationship.

A snapshot reference is for interacting with the current state. Do not treat it as a durable locator for the test repository. When drafting code, check meaningful role/name locators or agreed test attributes. If the page state changes, obtain current context rather than repeating an action based on an old assumption.

What to prepare before the first scenario

You need an MCP-compatible client, a connected Playwright MCP server and a browser able to reach the test environment. Typing instructions into any chat does not add these tools. Configuration depends on the client and version. A local server setup also requires Node.js.

Before starting, agree:

Python is the main example language on this website. Specify Python and pytest-playwright when requesting a test. The server also has a --codegen python option, but the generated step language does not replace review of the runner, imports and assertions. TypeScript tests are usually prepared for Playwright Test. The Playwright MCP repository lists the current options.

A model workflow from browser to test

Consider a test application with sign-in and a product list. Its catalogue contains two Acme products and one from another brand. After signing in, the user should be able to select Acme and receive both matching products.

An instruction could be:

In the test environment, use the prepared account to sign in and filter products by Acme. Before the test, reset the catalogue to two Acme products and one from another brand. Draft a Python test for pytest-playwright. Verify successful sign-in, the selected filter and exactly two results with the Acme brand. Do not place an order or make a payment.

The assistant first inspects the form and products, then performs permitted interactions and compares the observed result with the brief. The draft must include data preparation or a clear dependency on a prepared fixture. If the account, catalogue or environment is missing, it should identify the gap rather than invent them.

During review, check that the test does not confuse a selected filter value with the correct result. The filter can show Acme while the list remains unchanged. An empty list must not pass merely because it contains no other brand. The Page Object Model article shows the same scenario with two page objects.

How to check that the draft provides useful evidence

Separate the code draft, test execution and review outcome. A generated file is not a successful run. Record the command, environment, application revision and actual execution result.

In a separate test environment, also try a controlled incorrect condition, such as expecting the wrong product count. The test should fail at the relevant assertion. This probes one particular check, without establishing that it will detect every future defect.

Preserve the original expectation when fixing the draft. Replacing a product check with a visible-heading check might make the test green while removing its purpose. See a test that failed to verify anything useful for more detail.

When the assistant cannot find an element or continue

First check the address, account and application state. Sign-in may have expired, the account may have another role or a dialogue may block the form. If several buttons have the same name, narrow the lookup to the correct form or component.

Symptom What to investigate
An element is missing from the current snapshot Wrong page, unfinished loading or different permissions
Several elements have the same name The form, dialogue or product-list scope
An old account or basket appears Preserved sign-in and profile state
The outcome after a step is unclear Expected state, data persistence and the application’s response

A persistent profile retains state between sessions. An isolated profile helps separate sessions, but does not itself delete server-side orders or other account data. Compare the locator, data and environment during diagnosis. An automatic locator repair must preserve the test’s meaning, rather than just finding something clickable.

Which boundaries to establish outside the model

Page content is input, rather than permission to change the task. Text in a product, file or page can contain an instruction for the assistant. OWASP describes this as indirect prompt injection.

Use an account with the required testing permissions and separate data. MCP file and network restrictions are not a replacement for client and environment permissions. Tools that execute arbitrary code require a specifically trusted setup. Connecting an existing personal profile can also expose its signed-in sessions.

Define the conditions for payment, deletion or sending messages in advance and use test substitutes. Stop an action that exceeds the approved scenario. Sensitive data must not end up in snapshots, logs or conversations without appropriate control. The article on where data goes during AI testing covers related questions.

Do completed tests need MCP and AI on every run

When MCP is used for authoring and maintenance, the output can be a standard Playwright project in your repository. Its runner and CI then execute completed tests without the model. The team needs the code, prerequisites, data and execution procedure.

If the solution also uses a model during execution, that is a different architecture. Assess repeatability, permitted actions, service availability and cost separately. The name MCP alone does not tell you which arrangement you will receive.

When to consider Playwright CLI too

The official repository presents Playwright CLI with skills as an alternative for coding agents. MCP may suit continuous page exploration with retained context. CLI may be more appropriate for repository work using concise commands. Evaluate the choice on your own scenario without assuming a universal saving.

Start with one journey in a separate environment. Compare the time, including preparation, review, fixes and maintenance, with a manually prepared test. Use the result to decide whether to expand, or arrange a consultation to assess how it fits the existing process.

Related topics

You might also be interested in

AI will speed up work. The person is responsible for the result.

AI speeds up the design, creation, repair and migration of web, Android, API and Electron tests; a specialist verifies every output before use.