HOME

TheInfoList



OR:

Playwright is an
open-source Open source is source code that is made freely available for possible modification and redistribution. Products include permission to use and view the source code, design documents, or content of the product. The open source model is a decentrali ...
automation library for browser testing and
web scraping Web scraping, web harvesting, or web data extraction is data scraping used for data extraction, extracting data from websites. Web scraping software may directly access the World Wide Web using the Hypertext Transfer Protocol or a web browser. W ...
developed by
Microsoft Microsoft Corporation is an American multinational corporation and technology company, technology conglomerate headquartered in Redmond, Washington. Founded in 1975, the company became influential in the History of personal computers#The ear ...
and launched on 31 January 2020, which has since become popular among
programmer A programmer, computer programmer or coder is an author of computer source code someone with skill in computer programming. The professional titles Software development, ''software developer'' and Software engineering, ''software engineer' ...
s and
web developer A web developer is a programmer who develops World Wide Web applications using a client–server model. The applications typically use HTML, CSS, and JavaScript in the client, and any general-purpose programming language in the server. is used ...
s. Playwright provides the ability to automate browser tasks in
Chromium Chromium is a chemical element; it has Symbol (chemistry), symbol Cr and atomic number 24. It is the first element in Group 6 element, group 6. It is a steely-grey, Luster (mineralogy), lustrous, hard, and brittle transition metal. Chromium ...
,
Firefox Mozilla Firefox, or simply Firefox, is a free and open-source web browser developed by the Mozilla Foundation and its subsidiary, the Mozilla Corporation. It uses the Gecko rendering engine to display web pages, which implements curr ...
and
WebKit WebKit is a browser engine primarily used in Apple's Safari web browser, as well as all web browsers on iOS and iPadOS. WebKit is also used by the PlayStation consoles starting with the PS3, the Tizen mobile operating systems, the Amazon K ...
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 supports programming languages like
JavaScript JavaScript (), often abbreviated as JS, is a programming language and core technology of the World Wide Web, alongside HTML and CSS. Ninety-nine percent of websites use JavaScript on the client side for webpage behavior. Web browsers have ...
, Python, C# and
Java Java is one of the Greater Sunda Islands in Indonesia. It is bordered by the Indian Ocean to the south and the Java Sea (a part of Pacific Ocean) to the north. With a population of 156.9 million people (including Madura) in mid 2024, proje ...
, 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

@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.


History

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 Google LLC (, ) is an American multinational corporation and technology company focusing on online advertising, search engine technology, cloud computing, computer software, quantum computing, e-commerce, consumer electronics, and artificial ...
, 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.


Usage and examples

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: const = require('playwright'); (async () => )(); 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: const = require('@playwright/test'); test('basic test', async () => ); In this example, a test is written to navigate to https://example.com and check that the title of the page is "Example Domain".


Configuration

Playwright tests can be customized using a configuration file (playwright.config.js) that supports various options including: * Test timeout settings * Retry attempts for failed tests * Screenshot and video capture settings * Headless mode configuration * Test parallelization options An example configuration might look like: module.exports = ;


Debugging features

Playwright includes built-in debugging capabilities such as: * Screenshots captured on test failures * Video recording of test runs * Trace viewer for detailed step-by-step analysis * Debug mode with browser inspector * Console logs and network request monitoring


References

In this example, a test is written to navigate to https://example.com and check that the title of the page is "Example Domain".


References


Further reading

* *


External links

* * Graphical user interface testing Free software testing tools Software using the Apache license Free and open-source software Microsoft free software 2020 software Cross-platform free software Free software for Linux Free software for Windows Free software for macOS Free software programmed in TypeScript {{Portalbar, Free and open-source software