Using Playwright for visual tests
Node.js is not only a great basis for running logical tests but also for verifying visuals, such as those of a website running in a browser. A modern approach for browser automation is Playwright.
To use Playwright, you need to install the playwright
package from npm:
$ npm install playwright --save-dev
The playwright
package enables you to use Playwright in an existing application, which could also be inside existing tests such as unit tests executed with Jest using the jest-playwright-preset
package.
An even better setup can be achieved by using the @playwright/test
test runner package:
$ npm install @playwright/test --save-dev
This allows you to use the playwright
command-line utility. Ideally, run it with npx
as we did with the other tools:
$ npx playwright test
Running this will look for all files matching the same conventions as previously noted in the Jest and AVA sections. Every file ending with .test.js
or .spec.js
...