A major challenge in building quality software is ensuring that everything keeps working as expected — even as the codebase changes. That’s where end-to-end (E2E) tests come in. They help validate that your application behaves correctly from the user’s perspective.
E2E tests are great at catching bugs because they simulate real user interactions. They can detect issues that unit or integration tests might miss — like UI glitches, navigation problems, or broken user flows.
But let’s be honest: E2E testing isn’t always sunshine and rainbows. These tests can be slow, brittle, and hard to maintain. Writing and maintaining them is painful — especially in applications that change frequently or don’t have a solid testing foundation to begin with.

That’s where AI can help. It can assist in generating and maintaining E2E tests, freeing you to focus on designing high-impact scenarios that cover critical user paths and edge cases.
In this article, we’ll explore how to use AI with Playwright to generate E2E test code. You write the test scenarios, and AI handles the implementation.
Playwright + MCP
What is Playwright?
Playwright is a powerful open-source library for automating web browsers. It lets you interact with web pages, fill out forms, click buttons, and perform other actions — just like a real user would. Playwright supports multiple browsers (Chromium, Firefox, WebKit) and works with JavaScript, TypeScript, Python, Java, and .NET.

You can use it to simulate user interactions and verify your application’s behavior through automated tests.
And what is MCP?
MCP (Model Context Protocol) is a protocol that provides a standardized way to interact with AI models. It lets you send requests and receive responses from AI systems, abstracting away the complexity of the underlying implementation.

Think of it as an API for AI agents, where you define what tools it can use.
Using them together
Playwright enables browser automation. MCP enables seamless AI integration. Combined, they allow you to generate test scenarios and code using AI, giving the model the power to explore and test your application like a real human.
Setup
Let’s set up our project to use Playwright with MCP. We’ll install dependencies, configure the environment, and prepare everything to write AI-generated tests.
Prerequisites
- Node.js installed
- A code edittor (e.g. VS Code, Cursor)
- Copilot installed and configured
Install and configure Playwright
Create a new Node.js project:
| |
Install Playwright:
| |
Configure MCP in VS Code
Create a .vscode/mcp.json file with the following:
| |
Then, create a prompt file called generate-tests.prompt.md with this content:
| |
| |
Explore https://google.com
| |
Click on the search input, type “Playwright e2e tests”, and press Enter. Then, click on the ‘News’ tab to view the latest updates.
| |
Generate a Playwright test based on the actions performed.
| |
