Alert practice website
Practice the things that pop up: modal dialogs, toasts that vanish, tooltips that only exist on hover, and the browser’s own alert, confirm and prompt. Open the admin users screen
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
How to locate Alerts and modals
Overlays appear, sit somewhere else, and disappear
Modal dialogs are usually rendered at the end of <body>, not next to the button that opened them, so a locator scoped to the page section finds nothing. A well-built dialog has role="dialog" and takes its name from its title, which gives a test one clear scope for its buttons. The fragile one is a div layer whose close control is an unnamed glyph.
Toasts are timing problems. The message exists for a few seconds, so a test that looks too late finds nothing, and one that sleeps wastes time on every run. A toast with role="status" can be waited for; a bare div can only be raced.
Tooltips exist only while hovered. A test has to hover first, and the tip must be linked to its trigger to know which tip belongs to which control.
The browser’s alert, confirm and prompt are not HTML at all. No selector reaches them; every tool handles them through its driver, and an unhandled one blocks the page. Each framework does this differently, as the code below shows.
What a stable locator looks like
Scope to the dialog by its role and name, then find its buttons inside it. Wait for toasts by role, not with a sleep. Hover before asserting a tooltip. Register the native-dialog handler before the click that opens it.
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');In a real workflow
In the admin, deleting a user asks through the browser’s confirm, and saving a product asks in a modal dialog. Sign in, right-click a user and delete them, then cancel on the next one.
COR Lens generates locators for shadow DOM, iframes and tables, and grades each one. Click the alerts and modals above with it and compare its pick with yours.
Add to Chrome