Playwright (software)

Last updated
Playwright
Developer(s) Microsoft
Initial releaseJanuary 31, 2020;4 years ago (2020-01-31) [1]
Stable release
v1.45.1 [2] / 3 July 2024;5 months ago (2024-07-03)
Repository github.com/microsoft/playwright
Written in TypeScript
Operating system Microsoft Windows, macOS, Linux
Type Software testing framework for web applications
License Apache License 2.0
Website playwright.dev

Playwright is an open-source automation library for browser testing and web scraping [3] developed by Microsoft [4] [5] and launched on 31 January 2020, which has since become popular among programmers and web developers.

Contents

Playwright provides the ability to automate browser tasks in Chromium, Firefox and WebKit [6] 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. [7]

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

@playwright/test is a test runner with Jest-like assertions [8] 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. [9] It has capabilities like browser-specific tests, parallel test execution, [10] rich browser context options, snapshot testing, automatic retries and many more.

History

Playwright was announced by Microsoft in January 2020. [11] 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. [12] 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. [13]

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{chromium}=require('playwright');(async()=>{constbrowser=awaitchromium.launch();constpage=awaitbrowser.newPage();awaitpage.goto('https://example.com');awaitpage.screenshot({path:'example.png'});awaitbrowser.close();})();

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{test}=require('@playwright/test');test('basic test',async({page})=>{awaitpage.goto('https://example.com');awaitexpect(page).toHaveTitle('Example Domain');});

In this example, a test is written to navigate to 'https://example.com' and check if the title of the page is 'Example Domain'. [14]

Reception

Both Playwright and @playwright/test have been well received by the developer community. They are praised for their robustness, speed and widely used in the industry, playing an important role in web application testing and development.

Related Research Articles

In software testing, test automation is the use of software separate from the software being tested to control the execution of tests and the comparison of actual outcomes with predicted outcomes. Test automation can automate some repetitive but necessary tasks in a formalized testing process already in place, or perform additional testing that would be difficult to do manually. Test automation is critical for continuous delivery and continuous testing.

Ajax is a set of web development techniques that uses various web technologies on the client-side to create asynchronous web applications. With Ajax, web applications can send and retrieve data from a server asynchronously without interfering with the display and behaviour of the existing page. By decoupling the data interchange layer from the presentation layer, Ajax allows web pages and, by extension, web applications, to change content dynamically without the need to reload the entire page. In practice, modern implementations commonly utilize JSON instead of XML.

Selenium is an open source umbrella project for a range of tools and libraries aimed at supporting browser automation. It provides a playback tool for authoring functional tests across most modern web browsers, without the need to learn a test scripting language. It also provides a test domain-specific language (Selenese) to write tests in a number of popular programming languages, including JavaScript (Node.js), C#, Groovy, Java, Perl, PHP, Python, Ruby and Scala. Selenium runs on Windows, Linux, and macOS. It is open-source software released under the Apache License 2.0.

A browser extension is a software module for customizing a web browser. Browsers typically allow users to install a variety of extensions, including user interface modifications, cookie management, ad blocking, and the custom scripting and styling of web pages.

MDN Web Docs, previously Mozilla Developer Network and formerly Mozilla Developer Center, is a documentation repository and learning resource for web developers. It was started by Mozilla in 2005 as a unified place for documentation about open web standards, Mozilla's own projects, and developer guides.

QF-Test from Quality First Software is a cross-platform software tool for automated testing of programs via the graphical user interface. The program is specialized on cross-browser test automation of static and dynamic web-based applications. Version 4.1 added support for MacOS and the Apple Safari and Microsoft Edge browsers via the Selenium WebDriver. RESTful web service testing. From version 5.0, Windows applications can also be tested and modern C++ applications. Version 5.3 added support for the Chrome DevTools protocol, which allows browsers to be controlled using CDP drivers.

<span class="mw-page-title-main">TestComplete</span> Software test automation tool

TestComplete is a functional automated testing platform developed by SmartBear Software. TestComplete gives testers the ability to create automated tests for Microsoft Windows, Web, Android, and iOS applications. Tests can be recorded, scripted or manually created with keyword driven operations and used for automated playback and error logging.

<span class="mw-page-title-main">Chromium (web browser)</span> Open-source web browser project

Chromium is a free and open-source web browser project, primarily developed and maintained by Google. It is a widely-used codebase, providing the vast majority of code for Google Chrome and many other browsers, including Microsoft Edge, Samsung Internet, and Opera. The code is also used by several app frameworks.

<span class="mw-page-title-main">Play Framework</span> Open-source web framework written in Scala

Play Framework is an open-source web application framework which follows the model–view–controller (MVC) architectural pattern. It is written in Scala and usable from other programming languages that are compiled to JVM bytecode, e.g. Java. It aims to optimize developer productivity by using convention over configuration, hot code reloading and display of errors in the browser.

<span class="mw-page-title-main">Jasmine (software)</span> Open-source testing framework for JavaScript

Jasmine is an open-source testing framework for JavaScript. It aims to run on any JavaScript-enabled platform, to not intrude on the application nor the IDE, and to have easy-to-read syntax. It is heavily influenced by other unit testing frameworks, such as ScrewUnit, JSSpec, JSpec, and RSpec.

<span class="mw-page-title-main">Robot Framework</span> Type of test automation framework

Robot Framework is a generic software test automation framework for acceptance testing and acceptance test-driven development (ATDD). It is a keyword-driven testing framework that uses tabular test data syntax.

<span class="mw-page-title-main">Chromium Embedded Framework</span> Free and open-source software framework

The Chromium Embedded Framework (CEF) is an open-source software framework for embedding a Chromium web browser within another application. This enables developers to add web browsing functionality to their application, as well as the ability to use HTML, CSS, and JavaScript to create the application's user interface.

In computer programming, the async/await pattern is a syntactic feature of many programming languages that allows an asynchronous, non-blocking function to be structured in a way similar to an ordinary synchronous function. It is semantically related to the concept of a coroutine and is often implemented using similar techniques, and is primarily intended to provide opportunities for the program to execute other code while waiting for a long-running, asynchronous task to complete, usually represented by promises or similar data structures. The feature is found in C#, C++, Python, F#, Hack, Julia, Dart, Kotlin, Rust, Nim, JavaScript, and Swift.

A headless browser is a web browser without a graphical user interface.

JSON Web Token is a proposed Internet standard for creating data with optional signature and/or optional encryption whose payload holds JSON that asserts some number of claims. The tokens are signed either using a private secret or a public/private key.

<span class="mw-page-title-main">WebAssembly</span> Cross-platform assembly language and bytecode designed for execution in web browsers

WebAssembly (Wasm) defines a portable binary-code format and a corresponding text format for executable programs as well as software interfaces for facilitating communication between such programs and their host environment.

FastAPI is a high-performance web framework for building HTTP-based service APIs in Python 3.8+. It uses Pydantic and type hints to validate, serialize and deserialize data. FastAPI also automatically generates OpenAPI documentation for APIs built with it. It was first released in 2018.

<span class="mw-page-title-main">OneFuzz</span> Open-source fuzz testing platform

OneFuzz is a cross-platform free and open source fuzz testing framework by Microsoft. The software enables continuous developer-driven fuzz testing to identify weaknesses in computer software prior to release.

<span class="mw-page-title-main">Microsoft Power Platform</span> Family of business software products

Microsoft Power Platform is a collection of low-code development tools that allows users to build custom business applications, automate workflows, and analyze data. It also offers integration with GitHub, Microsoft Azure, Microsoft Dynamics 365, and Microsoft Teams, amongst other Microsoft and third-party applications.

References

  1. "v0.10.0 release". GitHub . Retrieved 1 June 2022.
  2. Tags · microsoft/playwright · GitHub
  3. Bansal, Mudit; Dar, Muhammad Ameen; Bhat, Moshin Manzoor; Sharma, Tushar; Uniyar, Rishita (2023). "Data Ingestion and Processing using Playwright". TechRxiv.
  4. Yegulalp, Serdar (30 September 2020). "Microsoft's Playwright simplifies tests for Python web apps". InfoWorld . IDG Communications. Retrieved 2 July 2023.
  5. Tung, Liam (1 October 2020). "Microsoft: Playwright for Python language lets you test web apps in all major browsers". ZDNET . Retrieved 2 July 2023.
  6. Judis, Stefan (22 October 2022). "Playwright, a Time-Saving End-to-End Testing Framework". The New Stack. Retrieved 2 July 2023.
  7. Tej, Krishna. "Playwright vs Cypress: A Comparison". BrowserStack . Retrieved 2 July 2023.
  8. "Assertions". Playwright. Microsoft . Retrieved 1 June 2023.
  9. "Library". Playwright. Microsoft . Retrieved 1 June 2023.
  10. "Parallelism and sharding". Playwright. Microsoft . Retrieved 1 June 2023.
  11. Attam, Arjun (30 September 2020). "Announcing Playwright for Python: Reliable end-to-end testing for the web". Microsoft DevBlogs. Microsoft . Retrieved 2 July 2023.
  12. Schiemann, Dylan (30 January 2020). "Microsoft Announces Playwright Alternative to Puppeteer". InfoQ . C4Media. Retrieved 2 July 2023.
  13. Gagan, Luc (1 July 2023). "A Comparative Analysis of Playwright Adoption vs Cypress and Selenium". Rayrun. Retrieved 2 July 2023.
  14. "toHaveTitle assertion". Playwright. Microsoft . Retrieved 1 June 2023.

Further reading