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.

members only

Keep reading with the full course

The Foundations track and the first 5 lectures of each framework are free. This lecture is part of the paid course, which unlocks every lecture, all three frameworks, and downloads.

See the options →