Software:Playwright

From HandWiki
Playwright
Playwright Logo.svg
Initial releaseJanuary 31, 2020; 4 years ago (2020-01-31)[1]
Written inTypeScript
Operating systemMicrosoft Windows, macOS, Linux
TypeSoftware testing framework for web applications
LicenseApache License 2.0


Playwright.[2] is a popular open-source automation library for browser testing and web scraping[3], developed by Microsoft[4][5]. It 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 has support for multiple programming languages, including 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[8]

@playwright/test

@playwright/test is a test runner with Jest (framework)-like assertions[9] that is built on top of the Playwright API. It is developed and maintained by the same team as Playwright. This test runner is tightly integrated with Playwright and is specifically designed for end-to-end testing[10]. It has capabilities like browser-specific tests, parallel test execution[11], rich browser context options, snapshot testing, automatic retries, and many more.

History

Playwright was announced by Microsoft in January 2020[12]. It was developed by a team of engineers who had previously worked on similar projects like Puppeteer at Google[13]. Since its inception, Playwright has been actively maintained and has seen rapid growth and adoption in the web testing community[14].

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 if the title of the page is 'Example Domain'[15].

Reception

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

References

  1. "v0.10.0 release". https://github.com/microsoft/playwright/releases/tag/v0.10.0. 
  2. "Playwright Website". https://playwright.dev/. 
  3. Bansal, Mudit; DAR, MUHAMMAD AMEEN; BHAT, MOHSIN MANZOOR; SHARMA, TUSHAR; UNIYAL, RISHITA (2023). "Data Ingestion and Processing using Playwright". TechRxiv. 
  4. Yegulalp, Serdar (September 30, 2020). "Microsoft’s Playwright simplifies tests for Python web apps". IDG Communications. https://www.infoworld.com/article/3583977/microsofts-playwright-simplifies-tests-for-python-web-apps.html. Retrieved July 2, 2023. 
  5. Tung, Liam (October 1, 2020). "Microsoft: Playwright for Python language lets you test web apps in all major browsers". ZDNET. https://www.zdnet.com/article/microsoft-playwright-for-python-language-lets-you-test-web-apps-in-all-major-browsers/. Retrieved July 2, 2023. 
  6. Judis, Stefan (October 22, 2022). "Playwright, a Time-Saving End-to-End Testing Framework". The New Stack. https://thenewstack.io/playwright-a-time-saving-end-to-end-testing-framework/. Retrieved July 2, 2023. 
  7. Tej, Krishna. "Playwright vs Cypress: A Comparison". BrowserStack. https://www.browserstack.com/guide/playwright-vs-cypress. Retrieved July 2, 2023. 
  8. "Why Playwright?" (in en). https://playwright.dev/docs/why-playwright. 
  9. "Assertions". https://playwright.dev/docs/test-assertions. 
  10. "Library". https://playwright.dev/docs/library#:~:text=Under%20most%20circumstances%2C%20for%20end,playwright%20(Playwright%20Library)%20directly.. 
  11. "Parallelism and sharding". https://playwright.dev/docs/test-parallel. 
  12. Attam, Arjun (30 September 2020). "Announcing Playwright for Python: Reliable end-to-end testing for the web" (in en). Microsoft. https://devblogs.microsoft.com/python/announcing-playwright-for-python-reliable-end-to-end-testing-for-the-web/. Retrieved July 2, 2023. 
  13. Schiemann, Dylan (January 30, 2020). "Microsoft Announces Playwright Alternative to Puppeteer". C4Media. https://www.infoq.com/news/2020/01/playwright-browser-automation/. Retrieved July 2, 2023. 
  14. Gagan, Luc (July 2023). "A Comparative Analysis of Playwright Adoption vs Cypress and Selenium". Rayrun. 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.. Retrieved July 2, 2023. 
  15. "toHaveTitle assertion". https://playwright.dev/docs/api/class-pageassertions#page-assertions-to-have-title. 
  16. Gagan, Luc (28 June 2023). "Comparing Automated Testing Tools: Cypress, Selenium, Playwright, and Puppeteer" (in en). Rayrun. https://ray.run/blog/comparing-automated-testing-tools-cypress-selenium-playwright-and-puppeteer#benchmarks. Retrieved July 2, 2023. 

External links

Official website for Playwright GitHub repository for Playwright