Playwright and MCP: How an AI Agent Checks the UI and the Database Without Hand-Written SQL Assertions

A green toast after checkout doesn't prove that an order was actually created. A new full-stack verification pattern hands both halves of the scenario to an AI agent: it walks through the UI with Playwright, then uses a second MCP server to check the database record, the order line items and the stock deduction. This cuts the amount of test code and removes manual SQL checks from end-to-end tests.

AI-processed from Habr AI; edited by Hamidun News
Playwright and MCP: How an AI Agent Checks the UI and the Database Without Hand-Written SQL Assertions
Source: Habr AI. Collage: Hamidun News.
Listen to article

A single green toast after clicking "Place order" doesn't mean the order was actually created. If the transaction rolled back, a queue dropped a message, and the UI still showed "success", an end-to-end test gives a false sense of reliability. That is why more and more teams are looking at full-stack verification, which checks not only the interface but also the actual state of the data in the database.

In the classic approach, the test infrastructure needs direct database access through an ORM or a low-level driver. Then the overhead begins: separate credentials, connection setup, hand-written SQL assertions, and query maintenance every time the schema changes. Formally, this solves the problem, but the cost grows with the number of scenarios. Every new end-to-end test becomes not just a check of user behavior but also a small project in test-code maintenance.

The article describes a lighter pattern: a single AI agent works with two MCP servers in sequence. First, it uses Playwright to run the scenario in the browser like an ordinary user: it fills the cart, goes through checkout, clicks the confirmation button and records the key signs of the outcome. Then the same agent switches to a server that can read the database structure and answer verification queries, without the tester writing SQL by hand.

Essentially, the agent only needs to state what has to be confirmed: whether an order record exists, whether the line items match, whether the product's stock was deducted, whether the payment status changed. This approach closes the main gap between "the UI showed success" and "the business operation actually completed." The agent can compare data from the interface with records in the tables, check side effects, and even account for asynchrony if the system doesn't write to the database instantly.

For product teams this matters most in scenarios where a single user-facing button triggers a chain of actions: creating an order, reserving inventory, writing to a logistics system, updating the customer's status. These are the places where expensive bugs most often appear, the kind an ordinary UI test doesn't catch.

The practical value of the pattern is that it lowers the barrier to full-stack testing. The team doesn't need to pull an ORM into the tests for just a few checks, or duplicate knowledge of the database schema in assertion code. Instead, there is a single verification layer expressed as intent: "a record should appear after the order is placed," "the number of line items should match," "the warehouse stock should decrease by one." If the schema changes, maintenance moves closer to the MCP server or to the data-access description, rather than being spread across dozens of tests. As a result, tests become shorter, clearer and closer to the language of the business.

This scenario does not replace basic engineering discipline, however. You can't rely on the AI agent alone: unit and integration tests are still needed to quickly localize errors at the level of functions, services and contracts. The agent's database access should be restricted, preferably read-only and only in a test environment. Predictability measures are also needed: stable test data, clear selection rules, and protection against the agent accidentally checking the wrong order in a shared database. Otherwise, a convenient tool will quickly turn into a source of noisy, hard-to-reproduce failures.

The main takeaway is simple: the next step in end-to-end testing is moving from checking screens to checking the real consequences of a user's action. Pairing Playwright with MCP makes that move noticeably cheaper, because it removes manual SQL from the tester's daily work and lets a single automation run from a button click to the fact of a database record. For teams testing payments, orders, bookings and other critical transactions, this is not just a handy technique but a way to reduce the number of false-positive tests and catch earlier the bugs that used to slip into production.

Story
ZK
Zhemal Khamidun — CPO at Alpina Digital, product manager of AlpinaGPT. Building AI products since 2019. Hamidun News is a pet project that grew into a production aggregator with 6,000+ readers.
✦ Hands-On AI Engineering · Hamidun Academy

Build & Ship Production AI Agents Without Boilerplate Code

Start your free 72-hour trial at Hamidun Academy (academy.hamidun.com) — interactive lessons on Claude Code & Cursor, live Tech Radar, and production agent templates.

Start 72h Free Trial →Vibe-Coding Intensive
What do you think?
Loading comments…