lecture 9 of 180 completed

Fixtures that build your test infrastructure

Your own fixtures turn repeated setup into something a test just asks for. Worker-scoped fixtures make expensive setup happen once.

What you'll learn

  • What worker scope changes about a fixture
  • Why worker scope is safe for reads and risky for writes
  • How fixtures become your framework layer

You already met fixtures as the things in the brackets: async ({ page }) => {}. That page is a fixture Playwright provides. Now you write your own, and this is where Playwright stops being a test runner and starts being a framework.

Here is the problem. Half your tests need a logged-in user. A quarter need a contact that already exists. You could put that in beforeEach, but then every test in the file pays for setup it may not need, and the test cannot say what it requires.

A custom fixture is setup that a test asks for by name.

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 →