Playwright is a UI automation test tool that supports Chrome, Edge, Firefox and Safari browsers. It was released in January 2020, has 74.7k stars on GitHub, and is fully open sourced and maintained by Microsoft.
Playwright uses the Chrome DevTools Protocol, Firefox Remote Debug Protocol & WebKit Debug Protocol to perform the browser automation tasks, and can run tests in parallel.
In addition to desktop E2E tests, Playwright also supports experimental component testing for React, Vue or Svelte, and integration testing with REST API’s. Playwright emulates mobile device user agent, screen size and viewport for mobile browser testing.
Like all good test frameworks, Playwright can capture screenshots (on demand and on failure), and can additionally record videos of test execution, which can be kept or discarded on failure.
Getting Started
Playwright is installable using Node package manager such as npm, Yarn or pnpm and interactively sets up a test project.
The sample test project can then be opened in the IDE of your choice and you can start to create page objects and build out your tests.
See the following guide for step by step instructions:
https://playwright.dev/docs/intro
Developing a framework
Playwright includes a built in assertion function (https://playwright.dev/docs/test-assertions) and supports page objects for maintainability and reusability (https://playwright.dev/docs/pom).
The tests can then be executed locally on the supported browsers (Chrome, Edge, Firefox, Safari) and additionally on cloud providers:
https://docs.saucelabs.com/visual-testing/integrations/playwright/
https://www.browserstack.com/docs/automate/playwright/getting-started/nodejs
https://www.lambdatest.com/support/docs/playwright-testing/
Playwright Typescript sample
Clone the repository from https://github.com/ObjectiveTester/AllThingsTesting.com-examples.git and start a terminal in the ‘PlaywrightTS’ directory and first run:npm install
npx playwright install
and then either:npm run playwright
to open the tests within the Playwright UI and run interactivelynpm run test
to execute the tests in headed modenpm run junit
to execute the tests and produce junit output for a CI platform
Summary
Playwright provides a rich set of functionality that allows testers and developers to rapidly build test suites covering component, integration and end-to-end tests across multiple browsers, supports screenshot and video recording, parallel execution, and is easily integrated into CI platforms and cloud execution providers.
Of the three frameworks I’ve investigated, Playwright would by my first choice for web application testing as it’s easy to develop with, and is notably faster in execution and has Auto-wait functionality to help with test stability.