Playwright and MCP: How an AI Agent Tests UI and Database Without Manual SQL Assertions
A green toast after checkout doesn't prove the order was actually created. The new full-stack verification pattern suggests delegating both parts of the…
AI-processed from Habr AI; edited by Hamidun News
One green toast after clicking the "Checkout" button doesn't mean the order was actually created. If the transaction rolled back, the queue lost a message, and the UI still showed "success," the end-to-end test gives a false sense of reliability. That's why more and more teams are looking toward full-stack verification, where not only the interface is checked, but also the actual state of data in the database.
In the classical approach, such verification requires the test infrastructure to have direct access to the DB through an ORM or low-level driver. Then the overhead begins: separate credentials, connection setup, manual SQL assertions, query maintenance with each schema change. Formally this solves the problem, but the cost grows with the number of scenarios.
Each new end-to-end test becomes not just a check of user behavior, but a mini-project of test code maintenance. The article covers a lighter pattern: one AI agent works sequentially with two MCP servers at once. First, through Playwright it executes a scenario in the browser as a regular user—fills the cart, goes through checkout, clicks the confirmation button, and captures key indicators of the result.
Then the same agent switches to a server that can read the database structure and answer verification queries without the tester writing SQL manually. Essentially, the agent only needs to formulate what exactly needs to be confirmed: does the order record exist, do the items match, was the product balance deducted, did the payment status change. This approach closes the main gap between "UI showed success" and "the business operation actually completed."
The agent can match data from the interface with records in tables, check side effects, and even account for asynchronicity if the system doesn't write to the DB instantly. For product teams this is especially important in scenarios where one user button triggers a chain of actions: order creation, inventory reservation, write to logistics system, customer status update. It's in such places that expensive bugs most often emerge, ones that regular UI tests don't catch.
The practical value of this pattern is that it lowers the bar for full-stack testing. Teams don't need to drag an ORM into tests just for a few checks and duplicate knowledge of the database schema in assertion code. Instead, there's a single verification layer at the level of intent: "after checkout an order record should appear," "the number of items should match," "warehouse balance should decrease by one."
If the schema changes, maintenance moves closer to the MCP server or the description of data access, rather than being spread across dozens of tests. As a result, tests become shorter, more understandable, and closer to business language. At the same time, this scenario doesn't override basic engineering discipline.
You can't rely only on the AI agent: unit and integration tests are still needed to quickly localize errors at the function, service, and contract level. Database access for the agent must be restricted, preferably read-only and only in a test environment. Measures for predictability are also needed: stable test data, clear selection rules, protection from the agent accidentally checking the wrong order in a shared database.
Otherwise, a convenient tool quickly becomes a source of noisy and hard-to-reproduce failures. The main conclusion here is simple: the next step in the evolution of end-to-end testing is the transition from checking screens to checking the real consequences of user action. The Playwright and MCP combination makes this transition significantly cheaper because it removes manual SQL from the tester's daily work and allows one automation to travel the path from button click to the fact of a database record.
For teams testing payments, orders, bookings, and other critical transactions, this isn't just a convenient technique but a way to reduce the number of false-positive tests and catch bugs earlier that previously leaked into production.
Want to stop reading about AI and start using it?
AI News is a curated feed of AI/tech news. Hamidun Academy teaches you to use AI systematically in your work.