Playwright Test Annotations

Sticky notes on a file folder tell a coworker what to do without opening the folder. Test annotations act as sticky notes on tests. A short label can skip a test, mark it as a known bug, flag it as slow, or group it under a name like smoke. The runner reads each note and adjusts its behavior.

The Annotation Family

test.skip   -> do not run this test
test.fixme  -> broken test, skip until fixed
test.fail   -> expected to fail (known bug)
test.slow   -> triple the timeout for this test
test.only   -> run only this test

Skipping a Test

A skipped test stays in the file and shows as skipped in the report. Conditions let a test skip itself on certain browsers.

test('uses a new browser feature', async ({ page, browserName }) => {
  test.skip(browserName === 'webkit', 'Feature missing in WebKit');
  await page.goto('/feature');
});

Marking a Fixme

The fixme note tells everyone that a test needs repair. Playwright skips the test and keeps it visible in the report as a reminder.

test('coupon applies discount', async ({ page }) => {
  test.fixme();
  // body waits for a repair
});

Expecting a Failure

The fail note flips the result. The test passes while the bug still exists and starts failing once developers fix the bug, which signals that the note is obsolete.

test('search handles symbols', async ({ page }) => {
  test.fail();
  await page.goto('/search?q=%26');
  await expect(page.getByText('Results')).toBeVisible();
});

Giving Slow Tests More Time

test('large file import', async ({ page }) => {
  test.slow();
  await page.goto('/import');
});

Running One Test Alone

The test.only note narrows a run to a single test during development. A forgotten only in shared code silently hides every other test. The config guards against this mistake.

export default defineConfig({
  forbidOnly: !!process.env.CI,
});

Tags for Grouping

A tag labels a test with a short name. The command line selects tests by that name.

test('user can log in', { tag: '@smoke' }, async ({ page }) => {
  await page.goto('/login');
});
npx playwright test --grep @smoke
npx playwright test --grep-invert @slow

Custom Annotations

A custom annotation links a test to an outside record, such as a ticket number. The report displays the link beside the test.

test('refund total', {
  annotation: { type: 'issue', description: 'BUG-1042' },
}, async ({ page }) => {
  await page.goto('/refund');
});

A Real-World Scenario

A team ships a release every Friday. Before the release, the group runs only the tests tagged @smoke, which cover login, search, and checkout in four minutes. The full suite runs overnight. A test for a coupon bug carries fixme until developers deliver a patch.

Quick Practice Task

Tag two of your tests with @smoke. Run only those tests with the --grep option and confirm that the report lists exactly two results.

Common Questions

Does a skipped test count as a failure?

No. The report shows skipped tests in their own count. A skipped test keeps its place in the file and returns to service when the note disappears.

Can a test carry several tags?

Yes. Pass an array such as { tag: ['@smoke', '@login'] } and select by either name from the command line.

What separates fixme from skip?

Both stop a test from running. The fixme note signals a repair job, and the skip note signals a deliberate condition such as an unsupported browser.

Key Takeaways

  • Annotations change how the runner treats a test without editing its steps.
  • Skip, fixme, fail, and slow cover the most common situations.
  • Tags let a team run focused groups of tests.
  • The forbidOnly setting blocks forgotten only calls in shared code.