Most QA teams do not start using Playwright automation when everything’s perfect. Playwright automation usually begins when the team is running out of time, and people are making a lot of changes to the features. The teams want to feel confident about the software before it is released. In these situations, it is not always possible to write every test from the beginning.
This is where Playwright’s Record & Play (Codegen) feature becomes useful, not as a shortcut, but as an accelerator. In real projects, Codegen helps teams quickly understand application flows, discover stable selectors, and bootstrap automation without slowing delivery.
This blog explains how Record & Play works in Playwright, when it genuinely helps, where it fails, and how experienced QA teams use it responsibly in production-grade frameworks.
- What the Record and Play (Codegen) feature is
- Prerequisites & Setup in Playwright (C#)
- Prerequisites for Playwright Automation in C#
- Installing Playwright in a C# .NET Project
- Installing and Using the Playwright CLI
- Quick overview of supported browsers (Chromium, Firefox, WebKit)
- Understanding the Record & Play Feature
- Example: What You Do vs. What Playwright Writes
- Recording Your First Test
- Reviewing the Generated Script in Playwright
- Real-Time Project Example: Selector Discovery
- Refining and Improving the Recorded Code in Playwright
- Writing More Meaningful Assertions Manually
- Improving Flaky or Dynamic Selectors
- Making the script more readable, maintainable, and scalable
- Moving Toward Framework-Level Code
- Advanced Recording Capabilities
- Integrating with Unit Test Frameworks
- Common Pitfalls & How to Fix Them
- Conclusion
What the Record and Play (Codegen) feature is
Playwright’s Record and Play feature allows testers to record real user interactions in the browser and automatically generate executable automation code in real time.
The Codegen tool allows testers to:
- Record user actions directly on the browser
- Automatically generate Playwright test scripts
- Capture locators, actions, and assertions in real time
- Learn Playwright syntax while interacting with the application
Instead of writing automation code from scratch, testers can simply interact with the application, and Playwright generates the corresponding test code. This makes test creation faster, especially for those who are new to Playwright or automation testing.
Why Recording Tools Matter in Automation Frameworks
Recording tools play an important role in automation frameworks, especially during:
- Initial test automation setup
- Learning a new automation tool
- Understanding application workflows
- Creating quick demos or proof-of-concepts
For QA engineers, recording tools:
- Reduce the initial learning curve
- Help identify stable locator strategies
- Speed up test creation
- Provide a quick starting point for automation scripts
In Playwright, the Codegen feature is not just a recorder; it generates readable and editable code, which still requires refactoring before it can be considered framework-ready, which makes it more useful compared to traditional record-and-play tools.
When recording makes sense vs. writing scripts manually (quick prototype vs. production-grade tests)
Although recording tools are powerful, they should be used wisely.
✔ When Recording Makes Sense
- Exploring a new or unfamiliar application
- Creating quick POCs or demo flows
- Discovering stable selectors in complex DOMs
- Reproducing bugs reported from production
- Helping manual testers transition into automation
❌ When Manual Scripting Is Better
- Building a long-term automation framework
- Writing regression or large-scale test suites
- Following Page Object Model (POM)
- Designing data-driven or role-based test coverage
Most experienced QA teams use Codegen as a starting point, then refactor the code manually to meet framework standards.
Prerequisites & Setup in Playwright (C#)
Prerequisites for Playwright Automation in C#
Before installing Playwright, make sure the system meets the basic requirements for running Playwright with C# dot NET. Having the right setup ensures a smooth automation experience and avoids common configuration issues.
Basic prerequisites include:
- .NET SDK (latest stable version recommended)
- Visual Studio or Visual Studio Code
- Basic knowledge of C# and object-oriented programming
- Understanding of UI automation and software testing concepts
These prerequisites are commonly available in most QA automation environments, making Playwright easy to adopt for existing C# automation projects.
Installing Playwright in a C# .NET Project
Playwright provides first-class support for .NET and C# automation testing. You can install Playwright directly into a new or existing .NET project.
High-level installation steps:
- Create a new .NET test project.
- Add the Playwright NuGet package to the project.
- Install Playwright browser dependencies.
- Verify installation by running a sample test.
dotnet new nunit -n PlaywrightDemo
cd PlaywrightDemo
dotnet add package Microsoft.Playwright
playwright installPlaywright integrates smoothly with popular .NET test frameworks like NUnit, MSTest, and xUnit, allowing QA engineers to run automated tests as part of their CI/CD pipelines.
Installing and Using the Playwright CLI
The Playwright CLI (Command Line Interface) is an essential tool that helps automate setup tasks and manage Playwright features efficiently.
With the Playwright CLI, you can:
- Install required browsers automatically
- Run Playwright tests from the command line
- Use the Codegen (Record and Play) feature
- Debug tests using headed or headless mode
The CLI simplifies day-to-day automation activities and is widely used in real-world Playwright projects to speed up development and execution.
Quick overview of supported browsers (Chromium, Firefox, WebKit)
Supported Browsers in Playwright
One of the biggest advantages of Playwright is its cross-browser testing capability.
Playwright supports:
- Chromium – Used for testing Chrome and Edge-based browsers
- Firefox – Ensures compatibility with Mozilla Firefox
- WebKit – Used for testing Safari-like behavior, especially on macOS
All browsers are installed and managed automatically by Playwright, ensuring consistent test results across different environments. This makes Playwright a powerful choice for teams that require reliable multi-browser automation using a single framework.
Why Proper Setup Matters
A correct setup:
- Prevents environment-related test failures
- Saves debugging time during execution
- Ensures smooth CI/CD integration
- Helps QA engineers focus on writing effective test cases
Once the prerequisites and setup are complete, you are ready to move forward with advanced Playwright features like Record and Play (Codegen) and framework design.
What Happens Behind the Scenes?
Behind the scenes, Playwright Codegen works by:
- Listening to DOM events triggered by user actions
- Capturing element attributes (role, text, labels, test IDs)
- Generating auto-waited actions to ensure stability
- Producing readable and editable automation scripts
Unlike traditional record-and-play tools that generate brittle scripts, Playwright focuses on reliable selectors and synchronization, which improves test stability.
💡 Real-time Insight:
When a tester clicks a button labeled “Submit”, Playwright prefers role-based or text-based locators instead of absolute XPaths, reducing flakiness.
Practical Benefits of Record and Play
🟢 For Beginners (Fast Learning Curve)
For testers who are new to automation or Playwright, Record and Play offers significant advantages:
- Faster onboarding into automation testing
- Less need to memorize Playwright syntax
- Immediate visual feedback while recording
- Helps understand how actions translate into code
Example:
A manual tester can record a login flow and instantly see how Playwright writes:
- Page navigation
- Input actions
- Assertions
This builds confidence and speeds up the transition from manual to automation testing.
await page.GotoAsync("https://example.com/login");
await page.GetByLabel("Email").FillAsync("user@test.com");
await page.GetByLabel("Password").FillAsync("password");
await page.GetByRole(AriaRole.Button, new() { Name = "Login" }).ClickAsync();
await Expect(page).ToHaveURLAsync("/dashboard");🔵 For Experienced QA Engineers
Even for senior QA engineers, the Record and Play feature is extremely useful.
Key benefits include:
- Quickly prototyping complex test flows
- Discovering reliable selectors
- Debugging flaky test cases
- Validating application behavior during exploration
Real-Time Project Example:
In real projects, experienced testers often
- Record a complex checkout flow
- Extract only the locator strategies
- Refactor the code into Page Object Model (POM)
- Add reusable methods and validations
This approach saves time without compromising framework quality.
Understanding the Record & Play Feature
Playwright’s Record & Play feature, also known as Codegen, is one of the most powerful productivity boosters in modern test automation. It allows you to interact with a real browser while Playwright automatically generates automation code in the background.
But recording is not magic. To use it effectively, you must understand what it actually does, where it shines, and where it falls short.
Let’s break it down clearly.
What the Record and Play capability actually does behind the scenes
When you run the Playwright codegen command, Playwright launches:
- A real browser instance
- A code generator process
- A selector engine
As you interact with the application, clicking buttons, filling inputs,
