Test Hooks
Special functions that run automatically before or after tests to handle setup and teardown.
What is Test Hooks?
What is Test Hooks?
Test hooks are lifecycle functions—such as beforeEach, afterEach, beforeAll, and afterAll—that a framework runs automatically around your tests to prepare and clean up state. They keep individual tests focused and independent by centralizing repetitive work like logging in, seeding data, or resetting the environment. Well-designed hooks are essential for test isolation, ensuring one test's leftovers never contaminate the next. Playwright's hooks and fixtures together give recorded suites a clean, reliable setup-and-teardown foundation.