How do I skip a test or run only one in Playwright?
Written by Jatin Thacker, Automation Architect · Updated
test.skip() and test.fixme() mark a test so Playwright does not run it, and test.only() makes Playwright run only the tests marked with it. Use skip when a test does not apply, fixme when it is known to be broken, and remove every only before you commit.This answer is one piece of Chapter 16: The Test Runner.
- Test Structure & Lifecycle
- playwright.config.ts Complete Reference
- Test Organization at Scale
- Tags, Grep, and the Suite You Actually Run
- What Runs Where, and What Serial Costs
- Practice and interview questions: Assertions & Test Runner
These are annotations: they change whether a test runs, and the report records the reason.
test.skip() says the test is not applicable here, for example in one browser or before a feature exists. test.fixme() says the test is broken and should not run until someone fixes it. Both appear in the report as skipped, so the suite still tells you they are there. test.fail() is different: the test does run, and Playwright checks that it fails.
test.only() focuses a test. When any test is focused, only focused tests run. That is handy while you work on one test, and dangerous if it reaches the main branch, because the pipeline silently runs one test instead of hundreds. Running with --forbid-only turns a leftover only into an error; it is common to enable it on CI.
The first run shows one test passing and two skipped. The second file has a plain test and a test.only: only the focused one ran. With --forbid-only, the same file refuses to run and exits with code 1.
import { test, expect } from '@playwright/test';
test('the cart starts empty', async ({ page }) => {
await page.goto('/catalog.html?mock=static&seed=42&autologin=1');
await expect(page.getByTestId('cart-total')).toHaveText('₹0');
});
test.skip('checkout flow, not built yet', async ({ page }) => {
await page.goto('/catalog.html?mock=static&seed=42&autologin=1');
});
test.fixme('search by SKU, known to be broken', async ({ page }) => {
await page.goto('/catalog.html?mock=static&seed=42&autologin=1');
});
// only.spec.js
import { test, expect } from '@playwright/test';
test('the header renders', async ({ page }) => {
await page.goto('/catalog.html?mock=static&seed=42&autologin=1');
await expect(page.getByTestId('site-header')).toBeVisible();
});
test.only('the cart starts empty', async ({ page }) => {
await page.goto('/catalog.html?mock=static&seed=42&autologin=1');
await expect(page.getByTestId('cart-total')).toHaveText('₹0');
});$ npx playwright test skip-fixme.spec.js Running 3 tests using 1 worker ok 1 [chromium] › skip-fixme.spec.js:3:1 › the cart starts empty (382ms) - 2 [chromium] › skip-fixme.spec.js:8:6 › checkout flow, not built yet - 3 [chromium] › skip-fixme.spec.js:12:6 › search by SKU, known to be broken 2 skipped 1 passed (1.5s) $ npx playwright test only.spec.js Running 1 test using 1 worker ok 1 [chromium] › only.spec.js:8:6 › the cart starts empty (403ms) 1 passed (1.6s) $ npx playwright test only.spec.js --forbid-only Error: item focused with '.only' is not allowed due to the '--forbid-only' CLI flag: "only.spec.js the cart starts empty" at only.spec.js:8
Practised in the full course: the drill Misunderstanding fixme.
See the chapterRelated questions
AI can write the test now. The job is knowing whether it checks anything. That's what the course teaches, one chapter at a time.
163 lessons · 226 drills · start free