1. Introduction
End-to-end testing has evolved dramatically, and Playwright stands at the forefront. Playwright offers a full ecosystem empowering developers to write, debug, and maintain tests with speed and reliability.
From its powerful test runner to rich developer tools like the VS Code extension, Codegen, UI Mode, and Trace Viewer, Playwright covers every phase of your testing journey. With the recent integration of Playwright MCP and the Playwright MCP server included in GitHub Copilot’s Coding Agent, AI-assisted development is now a reality, supercharging productivity and enabling smarter workflows.
This post walks you through the Playwright story: setting up tests, leveraging developer tools for code generation and debugging, and tapping into AI-powered automation.
🚀 New: Azure App Testing with Playwright
Playwright is built into Azure App Testing, a unified functional and performance testing service. It provides scalable, cloud-parallel test execution and CI-connected validation to speed up feedback. Learn more about Azure App Testing.2. Getting Started with Playwright
Playwright supports TypeScript/JavaScript, Java, Python, and .NET. This post uses TypeScript snippets, but check the docs for other languages.
To install Playwright:
npm init playwright@latest
This sets up browser binaries, a basic test suite, and a Playwright config file.
Your first test might look like this:
import { test, expect } from '@playwright/test';
test('homepage has title and links', async ({ page }) => {
// Navigate to the website
await page.goto('https://example.com');
// Verify the title
await expect(page).toHaveTitle(/Example/);
// Click a link and verify navigation
await page.getByRole('link', { name: 'More information' }).click();
await expect(page).toHaveURL(/.*more-info/);
});
Run your tests with:
npx playwright test
Or run a specific test file:
npx playwright test homepage.spec.ts
Install the Playwright for VS Code extension(1.6 million downloads) for:
- Visual Test Explorer to run and filter tests
- Inline test results and error messages
- One-click access to Trace Viewer
- Record tests using Codegen
- “Fix with AI” button for AI-assisted test fixes
With the extension, Playwright becomes a first-class citizen in your editor, making test authoring fast, fluid, and fun.
3. Test Authoring Made Easy: Codegen and UI Mode
Writing tests by hand can be tedious, especially when choosing selectors or remembering every interaction. Playwright makes this easier with Codegen.
Codegen: Record While You Interact
Use npx playwright codegen
to open your app and auto-generate test code as you click around.
npx playwright codegen https://your-app.com
Or use the Record New button in the VS Code testing sidebar.
This outputs functional test code in real time. Learn more about Codegen.
UI Mode: Visual Test Exploration
Run Playwright in interactive mode:
npx playwright test --ui
This launches a visual interface to:
- Browse and run tests with a click
- Instantly rerun tests in watch mode
- Filter tests by status, tags, or file
- Select locators directly from the UI
- Inspect each test step, including console output, errors, and network requests
- Examine DOM snapshots for visual debugging
UI Mode lets you explore, run, and debug tests with a time-travel experience. See UI Mode documentation.
Together, Codegen and UI Mode make writing and running tests fast, visual, and intuitive.
4. Reporting and Observability: HTML Report
Playwright’s HTML Report provides an interactive overview of each test run:
- Pass/fail status for every test
- Execution time for each test and suite
- Detailed error messages and stack traces
- Network requests and console logs
- Step-by-step breakdown of each test
- Direct links to trace files
Generate a HTML report by default with this configuration in your playwright.config.ts
:
export default defineConfig({
reporter: [
['html'],
['list'] // Also outputs results to the console
],
// ...other config
});
View the report after test execution:
npx playwright show-report
Filtering, grouping, and search make it easy to pinpoint issues and understand your test suite’s health.
5. Debugging and Observability: Trace Viewer
Flaky or failing tests are inevitable, but reproducing them doesn’t have to be hard. Playwright gives you first-class observability tools, especially the Trace Viewer.
What Is a Trace?
A trace is a full recording of a test run—every click, network request, and DOM snapshot. You can explore traces interactively to understand what happened before, during, and after a failure.
Enable tracing in your config:
use: {
trace: 'on-first-retry', // Record traces only when retrying a test
// Alternative options:
// 'on' - Record traces for all tests
// 'off' - Don't record traces
// 'retain-on-failure' - Record traces and only keep for failures
}
After a test failure, launch the trace viewer:
npx playwright show-trace trace.zip
You’ll see a timeline of actions, network activity, console logs, and more similar to what we saw in UI mode.
Traces on CI: No More “Works on My Machine”
Traces integrate seamlessly into CI:
- Failed tests generate a trace on the first retry
- Traces are saved as zip files and attached to CI artifacts
- Download and inspect them locally
This means even on headless CI runs, you get a visual record. Debugging regressions becomes fast and collaborative. Learn more in the CI traces guide. For cloud-scale parallel execution and CI-connected validation, check out Azure App Testing.
Traces make every test explain itself, locally or in CI. You get a story, not just a stack trace.
Copy as Prompt: AI Debugging
When you encounter a failure, use Copy as Prompt in the HTML Report, Trace Viewer, or UI Mode to generate a prompt for AI debugging. Share the context with AI tools like GitHub Copilot or other assistants.
Check out this video to learn more on debugging with AI using Playwright.
6. AI Native Testing with Playwright MCP
Playwright MCP: A Server for AI Browser Automation
Playwright MCP (Model Context Protocol) bridges AI agents and live browser sessions, letting AI interact with web apps via Playwright.
Playwright MCP empowers AI agents with:
-
- Complete browser state: Current page and accessibility tree
- Full suite of interaction tools: Click, type, wait, etc.
- Real-time page snapshots: Request current state anytime
Check out this video to easily install and run Playwright MCP: Playwright MCP in VS Code.
Use Cases for Playwright MCP
Playwright MCP unlocks intelligent agent behaviors:
- Automated test execution and exploration. Check out this video on letting AI explore your app and generate tests
- Test generation. Check out this video on AI-assisted test generation with Playwright MCP
- Automate manual tests from user stories or requirements. Check out this video
- Task automation: fill forms, submit data, walk through workflows. Check out this video on Filling out forms with Playwright MCP or this one on how AI agents can control your browser
If you want to learn more about MCPs check out this post on 10 MCP Servers to Get You Started.
7. GitHub Copilot’s Coding Agent: Powered by Playwright MCP
GitHub’s Copilot Coding Agent has Playwright MCP built in, enabling real-time app interaction. When you ask Copilot’s agent to implement a feature or fix a bug, it uses Playwright MCP to open the browser, navigate to the app, and verify the change.
Self-Verifying AI Workflows
With Playwright MCP, Copilot’s agent can:
- Launch a browser and load your app locally
- Interact with the UI it just modified
- Visually confirm the intended effect
- Use page state and logs to catch regressions
This creates a closed loop:
Prompt → Generate code → Run and observe app → Confirm success → Report back
No Extra Setup Needed
No configuration required. Assign an issue to Copilot Coding Agent, and it uses Playwright MCP to verify its work in a real browser.
Check out this video to see Copilot Coding Agent in action: GitHub Copilot Coding Agent with Playwright MCP.
With Playwright MCP, Copilot Coding Agent doesn’t just write code—it checks its work in real time.
8. Real-World Workflow: Putting It All Together
Building reliable end-to-end tests is only part of the story. In real projects, you need a seamless workflow integrating writing, debugging, and maintaining tests, while embracing AI-powered automation. Playwright’s ecosystem lets you do exactly that.
Real-World Workflow Checklist
- Bootstrap tests with Codegen: Quickly capture user flows and generate test code.
- Write and refine tests in VS Code: Organize, run, and debug tests with inline feedback and AI fixes.
- Explore tests with UI Mode: Browse, filter, and rerun tests interactively.
- Report and observe with the HTML Report: Get detailed, interactive overviews of your test suite.
- Debug failures with Trace Viewer: Inspect DOM snapshots, network activity, and logs frame by frame.
Amplify Your Workflow with AI Agents
Let AI take your testing to the next level:
- *Fix errors with AI assistance using the Fix with AI button in the VS Code extension, or the Copy as Prompt feature in the Trace Viewer, UI Mode and HTML Report
- With Playwright MCP, AI agents can explore your app, suggest new test cases, and generate new tests from natural language after first opening a browser and interacting with the app
- GitHub Copilot’s Coding Agent uses Playwright’s MCP to verify its work in a real browser after performing changes,ensuring that the code it generates is not only syntactically correct but also functionally verified against your application.
This fusion of human creativity and AI precision empowers teams to ship with confidence and speed.
Conclusion: Embrace the Future of End-to-End Testing with Playwright
Playwright is more than a testing framework, it’s a complete ecosystem streamlining every step of your end-to-end testing journey. From generating tests with Codegen, debugging with Trace Viewer, seamless editor integration, interactivity with UI Mode, and reporting with the HTML Report, Playwright equips you to build stable, reliable tests with a great developer experience.
With Playwright MCP, you’re collaborating with intelligent agents that interact with your app in a real browser, verify changes, and automatically run tests. The GitHub Copilot Coding Agent leverages Playwright MCP to open a browser and validate the task assigned to it, making it easier than ever to maintain high-quality software.
Whether starting your first test or managing a large suite, Playwright’s tools empower you to deliver quality software with confidence and speed.
Ready to get started? Dive in, explore the tools, and join the vibrant Playwright community pushing the boundaries of modern testing.
Install the Playwright MCP server today and experience the future of end-to-end testing with AI-powered automation.
0 comments
Be the first to start the discussion.