Playwright practice website
Every element on one page, each built well and built to break, with Playwright code for each group. Switch to v2 and see which locators survive.
Starter test: sign in and place an order (Playwright)
tests/checkout.spec.ts
import { test, expect } from '@playwright/test';
test('signs in and places an order', async ({ page }) => {
await page.goto('/practice/shop/sign-in');
await page.getByLabel('Email').fill('[email protected]');
await page.getByLabel('Password').fill('practice123');
await page.getByRole('button', { name: 'Sign in' }).click();
await expect(page.getByRole('heading', { name: 'Order history' })).toBeVisible();
await page.getByRole('combobox', { name: 'Search products' }).fill('Pocket');
await page.getByRole('option', { name: 'Pocket Speaker' }).click();
await page.getByTestId('add-to-cart').click();
await page.getByTestId('cart-link').click();
await page.getByTestId('checkout').click();
await page.getByLabel('Street address').fill('1 Main St');
await page.getByPlaceholder('City').fill('Springfield');
await page.getByPlaceholder('Postcode').fill('12345');
const card = page.frameLocator('iframe[title="Card details"]');
await card.getByLabel('Card number').fill('4242 4242 4242 4242');
await card.getByLabel('Expiry').fill('12/30');
await card.getByLabel('CVC').fill('123');
await page.getByTestId('place-order').click();
await expect(page.getByTestId('row-KG-2101')).toBeVisible();
});Shadow DOMMore Shadow DOM practice
Coupon fieldAn input and a button inside a shadow root.
Built well
Built to break
Two roots deepA button inside a root that sits inside another root.
Built well
Built to break
Date pickerThe same picker the admin product editor uses.
Built well
Built to break
Iframe inside a shadow rootCross the root, then switch into the frame.
Built well
Built to break
Design-system buttonThe label is slotted in from outside; the button lives in the root.
Built well
Built to break
Playwright code for this section
// Open roots are pierced automatically (XPath is the exception)
await page.getByLabel('Coupon code').fill('SAVE10');
await page.getByRole('button', { name: 'Apply coupon' }).click();
// Two roots deep: still one locator
await page.getByRole('button', { name: 'Add to wishlist' }).click();
// Each day is named with its full date
await page.getByRole('button', { name: 'December 12, 2026' }).click();
// Design-system button: the slotted label is in the page, the button in the root
await page.getByTestId('ds-control').click();
await page.locator('[data-testid="ds-button"] [slot="label"]').click();IframesMore Iframes practice
Card formUse the test card 4242 4242 4242 4242, any future expiry and any CVC.
Built well
Built to break
Nested framesA chat frame inside a help-center frame.
Built well
Built to break
Shadow root inside an iframeSwitch into the frame, then cross the root.
Built well
Built to break
Playwright code for this section
const card = page.frameLocator('iframe[title="Card details"]');
await card.getByLabel('Card number').fill('4242 4242 4242 4242');
await card.getByLabel('Expiry').fill('12/30');
await card.getByLabel('CVC').fill('123');
// Nested: one frameLocator per level
const chat = page.frameLocator('iframe[title="Help center"]')
.frameLocator('iframe[title="Chat"]');
await chat.getByLabel('Message').fill('Hi');
await chat.getByRole('button', { name: 'Send' }).click();DropdownsMore Dropdowns practice
Native selectA real <select> element.
Built well
Built to break
Searchable comboboxType to filter, then pick a suggestion.
Built well
Built to break
Multi-selectChoose several options; remove them from the chips.
Built well
Built to break
Menu that closes when you inspect itIt closes when the page loses focus. In DevTools, turn on "Emulate a focused page" to inspect it.
Built well
Built to break
Playwright code for this section
await page.getByLabel('Sort by').selectOption('phones');
await page.getByRole('combobox', { name: 'Search products' }).fill('cam');
await page.getByRole('option', { name: 'Cameras' }).click();
await page.getByTestId('multi-select').click();
await page.getByRole('option', { name: 'Audio' }).click();
await expect(page.getByRole('option', { name: 'Audio' }))
.toHaveAttribute('aria-selected', 'true');Web tablesMore Web tables practice
Sortable, editable tableSort by any column. Edit a customer name with the pencil.
Built well
| ORD-1001 | Ada Park | Paid | $19.50 |
| ORD-1002 | Bo Chen | Refunded | $56.50 |
| ORD-1003 | Cal Diaz | Pending | $93.50 |
| ORD-1004 | Dee Evans | Shipped | $130.50 |
| ORD-1005 | Eli Fox | Paid | $167.50 |
| ORD-1006 | Fay Gold | Refunded | $204.50 |
| ORD-1007 | Gus Hale | Pending | $241.50 |
| ORD-1008 | Ivy Ito | Shipped | $278.50 |
| ORD-1009 | Jon Kerr | Paid | $315.50 |
| ORD-1010 | Kai Lund | Refunded | $352.50 |
| ORD-1011 | Lia Moss | Pending | $389.50 |
| ORD-1012 | Max Nori | Shipped | $26.50 |
Built to break
Virtualized table500 orders, but only the rows in view are in the DOM.
Built well
Built to break
Paginated tableFind INV-1010: it is not on the first page.
Built well
| Order | Customer | Status | Total |
|---|---|---|---|
| INV-1001 | Ada Park | Paid | $19.50 |
| INV-1002 | Bo Chen | Refunded | $56.50 |
| INV-1003 | Cal Diaz | Pending | $93.50 |
| INV-1004 | Dee Evans | Shipped | $130.50 |
Built to break
Table of duplicate valuesFind the run on Firefox in Austin. Most cells repeat.
Built well
| Run | OS | Browser | City | Country |
|---|---|---|---|---|
| DUP-1 | Windows | Chrome | Pune | India |
| DUP-2 | Windows | Firefox | Pune | India |
| DUP-3 | macOS | Chrome | Pune | India |
| DUP-4 | Windows | Chrome | Austin | USA |
| DUP-5 | Linux | Firefox | Pune | India |
| DUP-6 | Windows | Chrome | Pune | India |
| DUP-7 | macOS | Safari | Austin | USA |
| DUP-8 | Windows | Firefox | Austin | USA |
Built to break
Playwright code for this section
// Find the record, not the position
const row = page.getByTestId('orders-table').getByRole('row', { name: /ORD-1003/ });
await row.getByRole('button', { name: 'Edit customer for ORD-1003' }).click();
await page.getByLabel('Customer for ORD-1003').fill('Zed Young');
await page.getByRole('button', { name: 'Save' }).click();
await expect(row).toContainText('Zed Young');
await page.getByRole('button', { name: 'Total' }).click();
await expect(page.getByRole('columnheader', { name: /Total/ }))
.toHaveAttribute('aria-sort', 'ascending');
// Virtualized: scroll until the row exists
await page.getByTestId('virtual-table').evaluate((el) => { el.scrollTop = 40 * 300; });
await expect(page.getByTestId('vrow-ORD-1301')).toBeVisible();XPathMore XPath practice
Value in a table rowGet the total for Bo Chen, wherever the row sits.
Built well
| Customer | Status | Total |
|---|---|---|
| Ada Park | Paid | $149.00 |
| Bo Chen | Shipped | $56.00 |
| Cal Diaz | Refunded | $899.00 |
| Dee Evans | Paid | $249.00 |
Built to break
Id that changes every build
Built well
Built to break
Text with stray spaces
Built well
Built to break
Repeated Edit linksEdit Bo Chen, not "the second one".
Built well
- Ada Park
- Bo Chen
- Cal Diaz
Built to break
- Ada ParkEdit
- Bo ChenEdit
- Cal DiazEdit
Inputs that differ by one attribute
Built well
Built to break
Text in other scriptsHindi, Chinese and accents are fine; a non-breaking space or curly quotes are not.
Built well
Built to break
Playwright code for this section
// Playwright treats a selector starting with // as XPath
const total = page.locator('//table[@data-testid="xp-table"]//tr[td[normalize-space()="Bo Chen"]]/td[3]');
await expect(total).toHaveText(/\$/);
await page.locator('//input[starts-with(@id, "search-")]').fill('headphones');
await page.locator('//div[span][normalize-space()="Save draft"]').click();
await page.locator('//li[span[normalize-space()="Bo Chen"]]//*[normalize-space()="Edit"]').first().click();
await page.locator('//label[normalize-space()="Text me"]/input[@name="notify" and @value="sms"]').check();Form controlsMore Form controls practice
Input with validationType something that is not an email, then leave the field.
Built well
Built to break
Radio buttons
Built well
Built to break
Checkbox
Built well
Built to break
File uploadThe fragile one hides its real input.
Built well
Built to break
Slider and date
Built well
Built to break
Playwright code for this section
const email = page.getByLabel('Work email');
await email.fill('not-an-email');
await email.blur();
await expect(email).toHaveAttribute('aria-invalid', 'true');
await expect(email).toHaveAccessibleDescription('Enter a valid email.');
await page.getByRole('radio', { name: 'Pro' }).check();
await page.getByRole('checkbox', { name: 'Subscribe to the newsletter' }).check();
await page.getByLabel('Product image').setInputFiles('fixtures/shoe.png');
await page.getByRole('slider', { name: /Stock level/ }).press('ArrowRight');
await page.getByLabel('Delivery date').fill('2026-12-24');Alerts and modalsMore Alerts and modals practice
Modal dialog
Built well
Built to break
ToastGone after three seconds.
Built well
Built to break
TooltipHover the icon.
Built well
Built to break
Browser alert, confirm and promptNative dialogs have no DOM.
Built well
Built to break
Playwright code for this section
await page.getByTestId('open-dialog').click();
const dialog = page.getByRole('dialog', { name: 'Delete this product?' });
await dialog.getByRole('button', { name: 'Cancel' }).click();
await expect(dialog).toBeHidden();
await page.getByTestId('save-changes').click();
await expect(page.getByTestId('toast')).toHaveText('Changes saved');
await page.getByRole('button', { name: 'Shipping info' }).hover();
await expect(page.getByRole('tooltip')).toHaveText('Ships in 2 business days');
page.once('dialog', (d) => d.accept()); // before the click
await page.getByTestId('confirm-button').click();
await expect(page.getByTestId('dialog-result')).toHaveText('Confirmed');Mouse hoverMore Mouse hover practice
Nested hover menuAccount → Security → Two-factor.
Built well
Built to break
Right-click menu
Built well
Built to break
Playwright code for this section
await page.getByRole('menuitem', { name: 'Account' }).hover();
await page.getByRole('menuitem', { name: 'Security' }).hover();
await page.getByRole('menuitem', { name: 'Two-factor' }).click();
await expect(page.getByTestId('menu-result')).toHaveText('Selected: Two-factor');
await page.getByTestId('context-area').click({ button: 'right' });
await page.getByRole('menu', { name: 'Row actions' })
.getByRole('menuitem', { name: 'Delete' }).click();
await expect(page.getByTestId('context-result')).toHaveText('Chose: Delete');Drag and dropMore Drag and drop practice
Drag to reorderDrag a row onto another. The good list also has move buttons.
Built well
Built to break
TabsThe fragile tabs change order on v2.
Built well
Built to break
Accordion
Built well
Built to break
Playwright code for this section
await page.getByTestId('drag-gift-guide').dragTo(page.getByTestId('drag-summer-sale'));
// Without a mouse: the list's move buttons
await page.getByRole('button', { name: 'Move Best sellers up' }).click();
await page.getByRole('tab', { name: 'Specs' }).click();
await expect(page.getByRole('tabpanel')).toContainText('200 gsm');
await page.getByRole('button', { name: 'Returns' }).click();
await expect(page.getByRole('region', { name: 'Returns' })).toBeVisible();WaitsMore Waits practice
Content that arrives lateTwo seconds after the page loads, or after Reload.
Built well
Built to break
Spinner
Built well
Built to break
Stacked toastsEach hides after 3 seconds. Two can show at once.
Built well
Built to break
List that loads as you scroll
Built well
- Product 1
- Product 2
- Product 3
- Product 4
- Product 5
- Product 6
- Product 7
- Product 8
- Product 9
- Product 10
Built to break
Playwright code for this section
// Assertions retry until the content arrives (5 seconds by default)
const recs = page.getByRole('region', { name: 'Recommendations' });
await expect(recs).toHaveAttribute('aria-busy', 'false');
await expect(recs.getByText('Aero Headphones')).toBeVisible();
await page.getByTestId('load-orders').click();
await expect(page.getByRole('progressbar', { name: 'Loading orders' })).toBeHidden();
await expect(page.getByTestId('orders-result')).toHaveText('3 orders found.');
await page.getByRole('button', { name: 'Load more' }).click();
await expect(page.getByTestId('lazy-item-20')).toBeVisible();
// Assert a toast before it hides, and pick the right one from the stack
await page.getByRole('button', { name: 'Both at once' }).click();
await expect(page.getByTestId('toast-shipped')).toHaveText('Order KG-2101 shipped.');
await expect(page.getByTestId('toast-shipped')).toBeHidden({ timeout: 5000 });Windows and tabsMore Windows and tabs practice
New tab
Built well
Open product in new tabBuilt to break
OpenPop-up windowType a reply in the pop-up and send it back.
Built well
Built to break
Playwright code for this section
// New tab from a target="_blank" link
const [tab] = await Promise.all([
page.context().waitForEvent('page'),
page.getByTestId('new-tab-link').click(),
]);
await expect(tab).toHaveURL(/\/practice\/shop\/product/);
await tab.close();
// Pop-up that replies to this page
const [popup] = await Promise.all([
page.waitForEvent('popup'),
page.getByTestId('popup-button').click(),
]);
await popup.getByLabel('Reply').fill('All good');
await popup.getByTestId('popup-send').click();
await expect(page.getByTestId('popup-reply')).toHaveText('Help window says: All good');SVG and canvasMore SVG and canvas practice
SVG icon button
Built well
Built to break
SVG bar chartClick Wednesday’s bar.
Built well
Built to break
CanvasClick the green tile.
Built well
Built to break
SVG inside a shadow root
Built well
Built to break
Playwright code for this section
await page.getByRole('button', { name: 'Delete item' }).click();
await expect(page.getByTestId('svg-delete-result')).toHaveText('Deleted');
// XPath needs name() or local-name() for SVG elements
await page.locator('//*[name()="svg"][@data-testid="sales-chart"]/*[name()="rect"][@data-testid="bar-wed"]').click();
await expect(page.getByTestId('chart-result')).toHaveText('Wed: 7 orders');
// Canvas: use the accessible buttons, or click by coordinates
await page.getByRole('button', { name: 'Green' }).click();
await page.getByTestId('tiles-canvas').click({ position: { x: 110, y: 40 } });
await expect(page.getByTestId('canvas-result')).toHaveText('Green tile');Hidden elementsMore Hidden elements practice
Hidden until you open it
Built well
Built to break
Covered by a bannerClick Subscribe, then accept the cookies first.
Built well
Built to break
Disabled until enabled
Built well
Built to break
Invisible real inputThe checkbox you see is a span; the real one is invisible.
Built well
Built to break
Text drawn by CSS
Built well
Built to break
Playwright code for this section
await page.getByTestId('edit-nickname').click();
await page.getByLabel('Nickname').fill('Sam');
// Close the overlay first, or the click is intercepted
await page.getByRole('dialog', { name: 'Cookie consent' })
.getByRole('button', { name: 'Accept cookies' }).click();
await page.getByTestId('subscribe').click();
await page.getByTestId('enable-editing').click();
await expect(page.getByLabel('Company name')).toBeEnabled();
await page.getByLabel('Company name').fill('Kestrel');
// check() works through the invisible input
await page.getByRole('switch', { name: 'Email alerts' }).check();
// CSS-drawn text is not in the DOM
const sale = await page.locator('.pr-pseudo-sale')
.evaluate((el) => getComputedStyle(el, '::before').content); // '"Sale"'Broken linksMore Broken links practice
Find the broken linksTwo of these five links answer 404.
Built to break
Link padded with spaces
Built well
Built to break
File download
Built well
Built to break
Playwright code for this section
// Request every link in the list; two answer 404
const hrefs = await page.getByTestId('link-list').locator('a')
.evaluateAll((links) => links.map((a) => a.href));
for (const href of hrefs) {
const res = await page.request.get(href);
expect.soft(res.status(), href).toBeLessThan(400);
}
await expect(page.getByRole('link', { name: 'Open cart' })).toHaveAttribute('href', '/practice/shop/cart');
await expect(page.getByTestId('track-order')).toHaveText('Track my order');
const [download] = await Promise.all([
page.waitForEvent('download'),
page.getByTestId('download-orders').click(),
]);
expect(download.suggestedFilename()).toBe('orders-sample.csv');Virtualized listsMore Virtualized lists practice
1,000-row virtualized listScroll to ORD-742 (Rosa Quinn). Rows outside the view are removed, not hidden.
Built well
Built to break
Playwright code for this section
const list = page.getByTestId('order-list');
const row = list.locator('[data-customer="Rosa Quinn"]');
// Scroll the list until the row is rendered, then use it
while (!(await row.count())) {
await list.evaluate((el) => el.scrollBy(0, el.clientHeight));
}
await expect(row).toContainText('ORD-742');Generated idsMore Generated ids practice
Profile formSame form twice. Switch to v2 and watch the ids on the right change.
Built well
Built to break
Playwright code for this section
// Labels and test ids are the same on every release
await page.getByLabel('Full name').fill('Ada Park');
await page.getByTestId('gen-email').fill('[email protected]');
await page.getByRole('button', { name: 'Save' }).click();
await expect(page.getByTestId('gen-result')).toHaveText('Profile saved.');Localized textMore Localized text practice
Checkout in two languagesUse the Language switch above. The same build serves both.
Built well
Checkout
Total: $149.00
Built to break
Checkout
Total: $149.00
Playwright code for this section
// Test ids survive the switch; text and names do not
for (const lang of ['en', 'de']) {
await page.goto(`/practice/localized-text?lang=${lang}`);
await page.getByTestId('l10n-email').fill('[email protected]');
await page.getByTestId('l10n-place-order').click();
await expect(page.getByTestId('l10n-result')).not.toBeEmpty();
}A/B variantsMore A/B variants practice
Newsletter sign-up, A/B testedv1 shows variant A, v2 variant B.
Built well
Built to break
Playwright code for this section
// Same locators for variant A and variant B
await page.getByTestId('ab-email').fill('[email protected]');
await page.getByTestId('ab-subscribe').click();
await expect(page.getByTestId('ab-result')).toHaveText('You are on the list.');
// Variant A only: page.getByRole('button', { name: 'Subscribe' })