Microsoft’s Playwright for Python and Its Role in Test Automation
Frontend testing has always been a routine task. Testing user scenarios for each product version in different browsers took great effort, time, and money. So, QA professionals started practicing automated end-to-end testing that checks browser performance by simulating user actions. Now, Microsoft’s Playwright for Python is gaining significance and competing with other popular tools (Selenium, Cypress, Puppeteer). What makes it unique and so convenient for testers?
What is automated end-to-end testing?
Many business models require quality software for dealing with customers and processing information. For example, in online banking, the data that customers enter when making payments must be updated and kept secure in reliable internal systems. There are many critical business processes, and the success of large corporations depends on them. That’s why they demand thorough end-to-end testing (E2E).
QA services involving E2E tests are performed through the user interface (UI) by QA specialists, not developers. They differ from unit and integration testing. If you compare the process to testing a car, unit testing checks the condition of separate parts (for example, the engine or transmission). End-to-end testing assesses how well the entire vehicle is working when the driver gets in and starts it. Even if we make sure that all parts of the car work fine individually, it doesn’t mean that they will function properly together. So, end-to-end testing is crucial.
Now imagine a situation where you must release and update new versions of a web app every week for five browsers and three operating systems. How do you test them all? Repeated manual tests would be tedious and time-consuming. Therefore, testing the performance of an app with its repetitive processes is a primary task. For any commercial version of software, end-to-end testing plays an essential role. It analyzes the entire app in an environment that accurately simulates key actions of real users (network interaction, database interaction, etc.).
According to RWS research, in 2020, 44% of IT firms automated 50% of their quality assurance services. Automation is only responsible for certain parts of the entire process. These are functional, regression, smoke, and API testing. A widespread problem is choosing the appropriate set of automation tools. There is a variety of testing needs that no single tool handles well enough. Microsoft’s Playwright for Python aims to solve these issues efficiently.
What is the purpose of Microsoft’s Playwright for Python?
Before creating Playwright, Microsoft’s experts surveyed a group of developers and QA engineers. They detected problems related to testing across multiple browsers. Playwright’s developers wanted a simpler API that would allow them to master automation. And these are not all the tool’s capacities.
Microsoft’s Playwright for Python: what makes it unique
The key technical challenge is the cross-platform WebKit engine that can function on three platforms. To support the API in WebKit, Chromium, and Firefox, the company develops, like in Andersen, browser automation protocols (Chrome DevTools, Juggler, and Web Inspector). The third vital component of Playwright is a library handling each protocol, gathering them together under an “umbrella” and providing one convenient API. So, a professional can test three different browsers.
Microsoft’s Playwright in Python has the following unique features:
Easy and affordable automation
Browser contexts are significant. Imagine you log in to a browser and see your sessions and cookies. Should a tester automate all this after the script is complete, they must close the browser and delete the entire folder with metadata. And then they need to open a new one with a new folder so that another browser does not cache this information. With context, you can do it much faster using a single browser. Various browser contexts do not overlap with each other.
The Playwright API exploits this idea to make web testing and browser automation seamless and accessible.
Safe automation without delays
Modern web apps are feature-rich and responsive. They send network requests and modify the document object model (DOM) based on user interaction. Asynchronous program behavior makes app automation somewhat unpredictable. Playwright for Python ensures automation without timeouts: it waits until the UI is ready and uses an architecture that can consider precise browser events (page transitions, network requests, and DOM changes).
Excellent performance in modern networks
Web solutions are constantly improving, and new features are added annually. Playwright automates them, including mobile window emulation browsing, geolocation, time-zone, and web resolutions. With mobile emulation, rendering occurs on both iPhone and other platforms. Playwright scripts can even capture, introduce changes to network activity, and automate scenarios on multiple pages.
Experts can create automated tests for Chromium, WebKit, and Mozilla Firefox. All of them support WebKit, so you can test rendering in Safari and on Windows and Linux computers. There are other handy “tricks” facilitating testers’ work: the Auto Waiting API for automatic form filling, the Accessibility API to check the accessibility of websites, and support for different selectors. Microsoft’s Playwright for Python supports uploading and submitting files, Shadow DOM, through which selectors work (by the way, it solved a big problem for the web testing community).
Selenium vs. Playwright
Playwright performs any automation task by default. Selenium is different: a tester has to wait for a button to appear before clicking it. As a result, before any click action, the specialist writes: “Wait until the element is visible | my_button_css”. This is a reason for Selenium’s unstable behavior. In Playwright, effectiveness is clear for each action keyword and includes many tests. This makes the transition to Playwright reasonable.
Speed and performance
Compared to Selenium, Playwright is faster. This provides seamless and rapid automation. Many automators take a break between actions to avoid errors, and Playwright could probably settle this issue. For example, the Checkly API and E2E monitoring platform did its experiment of checking a browser using various automation tools. The team performed short and long software performance testing for a demo version of the site and the app. It turned out that Puppeteer and Playwright scripts were especially fast in executing tasks.
But Playwright has a powerful speed advantage in longer scenarios.
The creators of Playwright added a convenient feature of linking selectors and referring to the previous selector result using ‘>>’. Another nice innovation in Playwright is a text search. It also lets you create your own “selector engines” to describe the commands for choosing a particular item on a page.
Advanced HTTP requests
Developers can make HTTP requests from the Robot Framework. In its turn, Playwright allows running them from the current browser context and getting a response. This opens up vast opportunities.
Implementing test automation successfully requires the right set of automation tools. This allows an organization to implement testing strategies successfully and fully realize the benefits of test automation. Microsoft’s Playwright for Python is a sure-fire way to achieve these goals.