Playwright (software)

Playwright is an open-source automation library for browser testing and web scraping developed by Microsoft and launched on 31 January 2020, which has since become popular among programmers and web developers.
Playwright provides the ability to automate browser tasks in Chromium, Firefox and WebKit with a single API. This allows developers to create reliable end-to-end tests that are capable of running in non-headless mode, as well as in headless mode for automation. Playwright has been compared to Cypress.
Playwright supports programming languages like JavaScript, Python, C# and Java, though its main API was originally written in Node.js. It supports all modern web features including network interception and multiple browser contexts and provides automatic waiting, which reduces the flakiness of tests.
@playwright/test is a test runner with Jest-like assertions developed and maintained by the Playwright team that is built on top of the Playwright API. This test runner is tightly integrated with Playwright and is specifically designed for end-to-end testing. It has capabilities like browser-specific tests, parallel test execution, rich browser context options, snapshot testing, automatic retries and many more.
Playwright was announced by Microsoft in January 2020. It was developed to address the need for a unified API for cross-browser testing and to overcome limitations in existing tools like Puppeteer and Selenium. A team of engineers, including those who had previously worked on Puppeteer at Google, contributed to its development. Playwright introduced features like automatic waits, multi-browser support, and network interception, making it a powerful tool for modern web testing. Since its inception, it has been actively maintained and has seen rapid growth and adoption in the web testing community.
The @playwright/test runner was released later as part of an effort to provide a more comprehensive solution for browser-based testing. Its development was largely based on the need to have a specialized runner that can leverage the full potential of the Playwright API and make end-to-end testing more robust and straightforward.
Playwright is primarily used for automating browser tasks, which can range from simple page navigation and content scraping to more complex operations like automated form submissions, user interactions and more. For instance, a simple JavaScript code snippet using Playwright might look like:
In this example, Playwright is used to open a Chromium browser, navigate to https://example.com, take a screenshot and save it as example.png.
@playwright/test further extends these capabilities by providing a test runner that allows developers to write and organize their tests in a more structured and scalable manner. An example test using @playwright/test might look like:
In this example, a test is written to navigate to https://example.com and check that the title of the page is "Example Domain".
Playwright tests can be customized using a configuration file (playwright.config.js) that supports various options including:
An example configuration might look like:
Playwright includes built-in debugging capabilities such as:
In this example, a test is written to navigate to https://example.com and check that the title of the page is "Example Domain".