lecture 15 of 200 completed

Hooks: setup that runs for you

beforeEach, afterEach, beforeAll and afterAll. Choosing between them is a decision about test independence.

What you'll learn

  • What beforeEach, afterEach, beforeAll and afterAll do
  • Why beforeEach protects test independence
  • Why every test gets its own fresh page

You write five tests for the contacts page. Every one begins with the same two lines. Copying them is tedious, and when the flow changes you edit five places.

A hook is code that runs around your tests automatically.

full course

Keep reading with the full course

The Foundations track and the first lessons in each framework are free. This lesson needs full course access. A course plan includes all lessons for Playwright, Cypress and Selenium.

See course plans →