Add global beforeEach / afterEach hooks using Playwright automatic fixtures
AI Summary
This video explains how to use Playwright’s automatic fixtures to apply setup and teardown logic to every test case without repeating code in each spec file. It begins with an example showing setup and teardown hooks in individual test files and then moves to a cleaner approach by creating a base test file with custom fixtures using Playwright’s “extend” feature. The video demonstrates how to centralize common beforeEach and afterEach logic into custom fixtures, including automatic fixtures that run irrespective of whether tests explicitly reference them. It also introduces tracking JavaScript errors in page tests with an “exception logger” automatic fixture, showing how to gather errors and attach them as test attachments for better reporting. The video highlights the benefits of using automatic fixtures to maintain clean, DRY test code and improve visibility into test errors, making it easier to monitor JavaScript issues in end-to-end tests. The content is from Checkle’s Playwright Tips series, which provides ongoing best practices for Playwright testing.