Test structure: describe, hooks, tags, annotations and skipping
Group Playwright tests with describe, share set-up with hooks, label them with tags, and mark tests that must wait with skip or fixme.
L1–L4 are part of the Pro pass
L0 Explain simply
Analogy: chapters, a bookmark, and sticky notes in a workbook. Loose pages are hard to use. Chapters group them. A bookmark jumps to one page. A sticky note marks the pages that matter today.
Daily List is a to-do list app. Tom has tests/tasks.spec.ts with twelve tests in one heap. Each test starts by opening the site. Mei, the test lead, wants a way to run only the smoke checks before a release.
What it is: Playwright is a library that drives a real browser. This slice is how you group tests, share setup, and mark tests you want to run or park. A is the chapter. A is the shared step. A test annotation can affect execution or simply add report metadata. Selenium and Cypress group tests too, and the method names differ.
Why it matters: Twelve copies of the same open-the-site lines drift apart the first time the address changes. One hook keeps that step in one place. Tags let Mei run a small set without commenting tests out.
Workbook pages stay in order. Playwright may run files side by side. A hook must not assume that test two sees what test one left behind.
(SYNTHETIC / TRAINING ONLY: Daily List and every person named here are made up.)
PLAIN WORDS · 7 in this section
- bookmark
- a saved web address in a browser
- workbook
- one file holding several linked grids of numbers
- playwright
- a free Microsoft tool that drives a browser for tests
- annotation
- a short note added to explain or comment
- metadata
- extra details that describe the main data
- selenium
- A free tool that drives a web browser for checks.
- cypress
- A free tool that drives a web browser for checks.
PICTURE IT
The picture is the one the lesson above opens with. The table below shows how each part of it matches the software.
THE REAL JOB Keeping a growing test file readable, runnable in parts and honest about tests that cannot run.
- Group with describe
- Share with a hook
- Label with a tag
- Pick with --grep
HOW THE PICTURE MAPS
| In the picture | In the software |
|---|---|
| Chapters | Describe blocks |
| A bookmark | A --grep run that jumps to chosen tests |
| Sticky notes | Tags and annotations |
| Setting the table before each page | A beforeEach hook |
WHERE THIS PICTURE STOPS
- A workbook is read in order, but Playwright may run tests side by side.
- A sticky note never changes a page, but test.skip changes whether the test runs.
- A loose bookmark is harmless, but a left-behind test.only hides tests.
HOOK
Chapters, sticky notes, bookmark.
REMEMBER IT THIS WAY
A rule of thumb: if you see this, think that.
If twelve tests start with the same two lines, move them into one beforeEach hook.
| In the trick | What it stands for |
|---|---|
| Same two lines | open the site, then log in |
| beforeEach hook | a hook that runs before each test |
A line that only one test needs should stay inside that test.
TELL A FRIEND
A workbook with chapters, sticky notes and a bookmark. Chapters group, notes label, and the bookmark takes you to the pages you choose.
OFTEN MIXED UP WITH Fixtures: shared setup without copy-paste. Hooks run the same set-up around every test. A fixture is set-up a test asks for by name, so only the tests that need it pay for it.
Sources & standards — 3 sources
- Market practice
Annotations (Playwright documentation) ↗ — Microsoft (Playwright) · Reviewed 6 November 2026: Complete extracted primary article; examples inspected, not executed. See v45 source analysis for version scope and documented source ambiguities; no upstream run claimed.
Primary source opened and operative text inspected on 6 November 2026. Scope: Complete extracted primary article; examples inspected, not executed. Current live Playwright documentation reflects 1.65 where stated; explicit older examples retain their version. Source inspection is not an execution or compatibility-test claim. See the completed v45 Playwright analysis for source discrepancies and exact reading boundaries.
- Market practice
Playwright Test class reference (Playwright documentation) ↗ — Microsoft (Playwright) · Reviewed 6 November 2026: beforeEach, step, fail and locks type definitions. See v45 source analysis for version scope and documented source ambiguities; no upstream run claimed.
Primary source opened and operative text inspected on 6 November 2026. Scope: beforeEach, step, fail and locks type definitions. Current live Playwright documentation reflects 1.65 where stated; explicit older examples retain their version. Source inspection is not an execution or compatibility-test claim. See the completed v45 Playwright analysis for source discrepancies and exact reading boundaries.
- Market practice
Command line (Playwright documentation) ↗ — Microsoft (Playwright) · Reviewed 6 November 2026: Complete extracted primary article; examples inspected, not executed. See v45 source analysis for version scope and documented source ambiguities; no upstream run claimed.
Primary source opened and operative text inspected on 6 November 2026. Scope: Complete extracted primary article; examples inspected, not executed. Current live Playwright documentation reflects 1.65 where stated; explicit older examples retain their version. Source inspection is not an execution or compatibility-test claim. See the completed v45 Playwright analysis for source discrepancies and exact reading boundaries.
PRACTISE AND KEEP
Sources for this topic — 3 sources
- Market practice
Annotations (Playwright documentation) ↗ — Microsoft (Playwright) · Reviewed 6 November 2026: Complete extracted primary article; examples inspected, not executed. See v45 source analysis for version scope and documented source ambiguities; no upstream run claimed.
Primary source opened and operative text inspected on 6 November 2026. Scope: Complete extracted primary article; examples inspected, not executed. Current live Playwright documentation reflects 1.65 where stated; explicit older examples retain their version. Source inspection is not an execution or compatibility-test claim. See the completed v45 Playwright analysis for source discrepancies and exact reading boundaries.
- Market practice
Playwright Test class reference (Playwright documentation) ↗ — Microsoft (Playwright) · Reviewed 6 November 2026: beforeEach, step, fail and locks type definitions. See v45 source analysis for version scope and documented source ambiguities; no upstream run claimed.
Primary source opened and operative text inspected on 6 November 2026. Scope: beforeEach, step, fail and locks type definitions. Current live Playwright documentation reflects 1.65 where stated; explicit older examples retain their version. Source inspection is not an execution or compatibility-test claim. See the completed v45 Playwright analysis for source discrepancies and exact reading boundaries.
- Market practice
Command line (Playwright documentation) ↗ — Microsoft (Playwright) · Reviewed 6 November 2026: Complete extracted primary article; examples inspected, not executed. See v45 source analysis for version scope and documented source ambiguities; no upstream run claimed.
Primary source opened and operative text inspected on 6 November 2026. Scope: Complete extracted primary article; examples inspected, not executed. Current live Playwright documentation reflects 1.65 where stated; explicit older examples retain their version. Source inspection is not an execution or compatibility-test claim. See the completed v45 Playwright analysis for source discrepancies and exact reading boundaries.
Deepest material on this page: L4 — Standards & sources. Where a topic stops short of implementation depth, that is a deliberate coverage decision, not an oversight — see coverage.