Back to All Questions
Question 29 of 100
Framework
Beginner
What is test.describe() in Playwright?
The Answer
`test.describe()` groups related tests together, creating a named block. It helps organize tests logically and allows shared hooks (beforeEach/afterEach) that only apply to tests within that group.
Deep Dive Explanation
You can nest `test.describe()` blocks for sub-grouping. Use `test.describe.only()` to run a single group during development, or `test.describe.configure({ mode: 'parallel' })` to run tests within a group in parallel.
example.spec.ts
import { test, expect } from '@playwright/test';
test.describe('User Authentication', () => {
test.beforeEach(async ({ page }) => {
await page.goto('/login');
});
test('valid login', async ({ page }) => {
await page.fill('#email', 'user@test.com');
await page.fill('#pass', 'password');
await page.click('[type=submit]');
await expect(page).toHaveURL('/dashboard');
});
test('invalid login shows error', async ({ page }) => {
await page.fill('#email', 'wrong@test.com');
await page.fill('#pass', 'wrong');
await page.click('[type=submit]');
await expect(page.getByText('Invalid credentials')).toBeVisible();
});
});