Playwright (software)
{{Short description|End-to-end testing framework}}
{{Infobox software
| title = Playwright
| logo = Playwright_Logo.svg
| developer = Microsoft
| released = {{Start date and age|2020|01|31}}{{cite web|title=v0.10.0 release|url=https://github.com/microsoft/playwright/releases/tag/v0.10.0|website=GitHub|access-date=1 June 2022}}
| latest release version = {{wikidata|property|reference|edit|P348}}
| latest release date = {{start date and age|{{wikidata|qualifier|P348|P577}}|df=yes}}
| repo = {{URL|https://github.com/microsoft/playwright}}
| programming language = TypeScript
| operating system = Microsoft Windows, macOS, Linux
| genre = Software testing framework for web applications
| license = Apache License 2.0
| website = {{URL|https://playwright.dev/}}
}}
Playwright is an open-source automation library for browser testing and web scraping{{Cite journal|last1=Bansal|first1=Mudit|last2=Dar|first2=Muhammad Ameen|last3=Bhat|first3=Moshin Manzoor|last4=Sharma|first4=Tushar|last5=Uniyar|first5=Rishita|title=Data Ingestion and Processing using Playwright|year=2023|journal=TechRxiv}} developed by Microsoft{{cite web|last=Yegulalp|first=Serdar|date=30 September 2020|title=Microsoft's Playwright simplifies tests for Python web apps|url=https://www.infoworld.com/article/2260489/microsofts-playwright-simplifies-tests-for-python-web-apps.html|website=InfoWorld|publisher=IDG Communications|access-date=2 July 2023}}{{cite web|last=Tung|first=Liam|date=1 October 2020|title=Microsoft: Playwright for Python language lets you test web apps in all major browsers|url=https://www.zdnet.com/article/microsoft-playwright-for-python-language-lets-you-test-web-apps-in-all-major-browsers/|website=ZDNET|access-date=2 July 2023}} 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{{cite web|last=Judis|first=Stefan|date=22 October 2022|title=Playwright, a Time-Saving End-to-End Testing Framework|url=https://thenewstack.io/playwright-a-time-saving-end-to-end-testing-framework/|website=The New Stack|access-date=2 July 2023}} 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, 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{{cite web|title=Assertions|url=https://playwright.dev/docs/test-assertions|website=Playwright|publisher=Microsoft|access-date=1 June 2023}} 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.{{cite web|title=Library|url=https://playwright.dev/docs/library#:~:text=Under%20most%20circumstances%2C%20for%20end,playwright%20(Playwright%20Library)%20directly|website=Playwright|publisher=Microsoft|access-date=1 June 2023}} It has capabilities like browser-specific tests, parallel test execution,{{cite web|title=Parallelism and sharding|url=https://playwright.dev/docs/test-parallel|website=Playwright|publisher=Microsoft|access-date=1 June 2023}} rich browser context options, snapshot testing, automatic retries and many more.
History
Playwright was announced by Microsoft in January 2020.{{cite web|last=Attam|first=Arjun|date=30 September 2020|title=Announcing Playwright for Python: Reliable end-to-end testing for the web|url=https://devblogs.microsoft.com/python/announcing-playwright-for-python-reliable-end-to-end-testing-for-the-web/|website=Microsoft DevBlogs|publisher=Microsoft|access-date=2 July 2023}} 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.{{cite web|last=Schiemann|first=Dylan|date=30 January 2020|title=Microsoft Announces Playwright Alternative to Puppeteer|url=https://www.infoq.com/news/2020/01/playwright-browser-automation/|website=InfoQ|publisher=C4Media|access-date=2 July 2023}} 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.{{cite web|last=Gagan|first=Luc|date=1 July 2023|title=A Comparative Analysis of Playwright Adoption vs Cypress and Selenium|url=https://ray.run/blog/the-rapid-adoption-of-playwright-test-in-software-qa#:~:text=it's%20worth%20noting%20that%20playwright's%20github%20stars%20have%20been%20growing%20at%20a%20faster%20rate%20than%20cypress%20and%20selenium|website=Rayrun|access-date=2 July 2023}}
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 () => {
const browser = await chromium.launch();
const page = await browser.newPage();
await page.goto('https://example.com');
await page.screenshot({ path: 'example.png' });
await browser.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 }) => {
await page.goto('https://example.com');
await expect(page).toHaveTitle('Example Domain');
});
In this example, a test is written to navigate to https://example.com
and check that the title of the page is "Example Domain".{{cite web|title=toHaveTitle assertion|url=https://playwright.dev/docs/api/class-pageassertions#page-assertions-to-have-title|website=Playwright|publisher=Microsoft|access-date=1 June 2023}}
=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 = {
testDir: './tests',
timeout: 30000,
retries: 2,
use: {
headless: true,
screenshot: 'only-on-failure',
video: 'retain-on-failure',
},
};
=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{{cite web|title=How to Use Playwright for End-to-End Testing|url=https://www.roundproxies.com/blog/how-to-use-playwright/|website=roundproxies.com|date=6 January 2025|access-date=6 February 2025}}
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".{{cite web|title=toHaveTitle assertion|url=https://playwright.dev/docs/api/class-pageassertions#page-assertions-to-have-title|website=Playwright|publisher=Microsoft|access-date=1 June 2023}}
References
{{Reflist}}
Further reading
- {{Cite book|author-first=Eran|author-last=Kinsbruner|year=2022|title=A Frontend Web Developer's Guide to Testing: Explore leading web test automation frameworks and their future driven by low-code and AI|publisher=Packt Publishing|isbn=978-1803238319}}
- {{Cite book|author-first=Daniel|author-last=Irvine|year=2023|title=Svelte with Test-Driven Development: Advance your skills and write effective automated tests with Vitest, Playwright, and Cucumber.js|publisher=Packt Publishing|isbn=978-1837638338}}
External links
- {{Official website|https://playwright.dev/}}
- {{GitHub|microsoft/playwright}}
Category:Graphical user interface testing
Category:Free software testing tools
Category:Software using the Apache license
Category:Free and open-source software
Category:Microsoft free software
Category:Cross-platform free software
Category:Free software for Linux
Category:Free software for Windows
Category:Free software for macOS
Category:Free software programmed in TypeScript
{{Microsoft development tools}}
{{Microsoft FOSS}}
{{Portalbar|Free and open-source software}}