/playwright-adventures

Playwright demos and tips such as how to run in docker, how to get code coverage, etc

MIT LicenseMIT

Playwright adventures

Build and test the demo apps Markdown link check Prettier check

License: MIT GitHub Sponsors LinkedIn

Description

Playwright enables reliable end-to-end testing for modern web apps and it has become my preferred approach to test web apps. This repo aims to consolidate and share some of the experiences I've had and the solutions I've come up with whilst using Playwright.

My experiences with Playwright focused on using it as the test tool whilst developing web apps, where the main goal was to get better tests, including Visual Regression and Accessibility tests, which could run on a developer's machine as part of their development loop as well as run as part of the build pipeline of the web app, before the app is even deployed to an environment.

Important

Although the code demos presented here use Angular for the target app of the Playwright tests, the Playwright concepts that are demoed are frontend framework agnostic which means they and can be applied to any frontend framework.

Playwright demos

Demo Description
code-coverage-with-monocart-reporter Playwright code coverage using monocart-reporter.
code-coverage-with-istanbul-via-webpack-babel-plugin Playwright code coverage using Istanbul via Webpack Babel plugin.
docker Run Playwright tests in Docker. Also shows how to use Playwright tests UI mode in Docker. Especially helpful to eliminate screenshot differences when running the tests across different Operating Systems. For instance, if you develop in Windows but your CI runs on Linux.
stale-screenshots-cleanup Delete stale Playwright test screenshots.
fixtures Shows useful Playwright fixtures you can reuse:
- time/date emulation: so that you can do reliable asserts on screenshots or text that contains time/date information;
- capture console messages: so that you can assert on console messages.
- fail tests upon unexpected console messages: allows you to define allowed console messages and will fail the tests if any unexpected console message is produced. Good to catch left over debug/temp console messages.
- capture page error: so that you can assert on uncaught exceptions.
- fail tests on page errors: fails tests if any uncaught exception is produced.
- project name: allows you to control test behaviour depending on the Playwright project.
- annotations: shows how to add custom annotations to tests.
monocart-reporter-advanced-config Shows some advanced features of the monocart-reporter HTML report:
- add report metadata.
- customize the style of test tag.
- automatically collect test comments and add them to the test report.
accessibility-axe How to use Playwright for accessiblity testing using the @axe-core/playwright npm package.
accessibility-lighthouse How to use lighthouse with Playwright for accessiblity, SEO, performance and best-practices recommendations.

Tips

Learn more about Playwright