Playwright for Performance Testing Live Websites
The Power and Simplicity of Playwright
Playwright is a single tool that provides comprehensive support for both Chromium-based browsers like Edge and Chrome. This was a critical factor for us, as it ensured we could run consistent, reliable tests across our primary development platforms. Installing it is as easy as an npm command, which allows developers to get started quickly without a complex setup process.
For our team, two features were particularly powerful for creating performance tests. First, the Codegen feature, and its accompanying VS Code extension allow us to record interactions with a website and automatically generate clean, asynchronous code. This is a huge time-saver when creating complex test scenarios. Additionally, Playwright’s auto-wait capability automatically waits for elements to be actionable before performing an action, which makes our tests more resilient and helps prevent the kind of flakiness that often plagues web testing.
PlayWright allows you to easily record interactions on website and generates nice async code
Navigating the Inevitable Challenges
While Playwright is a fantastic tool, using it for performance testing on live sites isn’t without its challenges. Even with powerful tools like Codegen, real-world websites don’t always behave predictably. A new banner might appear, or a layout could shift slightly, meaning we often had to manually modify the generated code to make certain steps optional or more robust.
Another significant consideration was the inherent overhead. Every command between Playwright and the browser is an Inter-Process Communication (IPC) call. For most interactions, this is a non-issue, but for critical performance measurements, this overhead can skew results. In these specific cases, we found a more effective but complicated workaround: we would inject JavaScript directly into the site to perform the measurements in the browser’s own context. This sacrifice meant we couldn’t use all of Playwright’s convenient async APIs for those particular tasks, but it provided a more accurate and reliable performance reading.
Sometimes we have to use evaluate() to inject code directly in the web site to avoid IPC cost skewing the results
Ultimately, our solution was a hybrid approach. We leveraged Playwright’s robust IPC-based APIs for all standard interactions—like navigating to pages and logging in—and reserved the more complex JavaScript injection for the specific, performance-critical sections of the site that required precise measurement. This strategy allowed us to take advantage of Playwright’s many strengths while successfully addressing its limitations for our very specific performance testing needs.
Tests results can be seen in the browser and you can make your own custom output