Introduction to Microsoft Playwright and its features in brief — Part 01
Microsoft Playwright was released in 2011 as an open-source project built on top of Puppeteer. It is relatively new on the market but has quickly gained popularity. The release history can be found in their official GitHub Repository.
Cross-browser and Cross-language
Playwright started as a Javascript-based library, but they expanded it to support TypeScript, Python, .NET, and Java. The most interesting thing is that the playwright community has also built a Go Library. The goal of Playwright is to provide developers and testers with a single API to automate their web applications across all modern rendering engines, including Chromium, WebKit, and Firefox.
Cross-platform
It is a cross-platform automation library, as it can run on Windows, Linux, and macOS, locally or in CI. Playwright launches headless browsers by default. Headless browsers do not display the UI, so it is necessary to use the command lines. Only one line in the configuration file needs to be changed to switch between headless and non-headless modes.
Test Mobile Web
It uses Native mobile emulation of Google Chrome for Android and Mobile Safari to test on the Mobile Web. The same rendering engine also works on Desktops and in the Cloud.
Auto-wait
Unlike other frameworks or libraries, Playwright waits for the elements to be actionable before performing actions automatically. This feature is called Playwright Auto-wait. It auto-waits for all the relevant checks to pass and only then performs the requested action. If the required checks do not pass within the given timeout, the action fails with a TimeoutError.
Dynamic Web Assertions
In the case of assertions, the checks are retried automatically until the required conditions are met. Playwright Test uses the expect the library to perform the test assertions. This library has a set of matchers that can apply to different scenarios. When it comes to tracing, it provides captured execution traces, videos, and screenshots to get rid of the flakes.
Supports for iFrame and Shadow DOM
The playwright is fully supported by iFrames and Shadow DOM. Therefore, the advanced test scripts can be executed seamlessly in iFrames and Shadow DOMs, even in multiple tabs.
Browser Context and Authentication Reusability
Tests are executed under full isolation since it creates a fresh browser context for each test. Creating a new browser context takes only a handful of milliseconds. Repetitive log-in operations can also be bypassed by reusing the authentication state of the context. This saves a considerable amount of execution time.
Conclusion
This is the first article in this Playwright series, and it will continue until a hybrid automation framework is built using Playwright, Allure reports, and Gitlab CI. So keep tuned in.