← Back to library
Playwrightfixturesintermediatev1.20+
Group tests with test.describe
Use test.describe to group related tests, share hooks, and produce readable nested report output.
1import { test, expect } from '@playwright/test';
2
3// test.describe groups tests and scopes beforeEach/afterEach.
4// Report shows: "Checkout > with items > shows total price"
5test.describe('Checkout', () => {
6 test.describe('with items in the cart', () => {
7 test.beforeEach(async ({ page }) => {
8 await page.goto('/cart?prefill=true');
9 });
10
11 test('shows the total price', async ({ page }) => {
12 await expect(page.getByTestId('cart-total')).toBeVisible();
13 });
14
15 test('applying a coupon reduces the total', async ({ page }) => {
16 await page.getByLabel('Coupon code').fill('SAVE10');
17 await page.getByRole('button', { name: 'Apply' }).click();
18 await expect(page.getByTestId('discount-row')).toBeVisible();
19 });
20 });
21
22 test('empty cart shows empty-state message', async ({ page }) => {
23 await page.goto('/cart');
24 await expect(page.getByTestId('empty-cart-message')).toBeVisible();
25 });
26});#test.describe#group#nested#organisation