Component Lab D · Interruptions and feedback

Dialogs, Modals, and Toasts

Handle native browser dialogs, accessible application modals, and deterministic toast notifications with visible captured outcomes.

PRACTICE FIXTURE — intentionally built for automation practice

Native browser dialogs

Each browser-owned dialog writes its accepted or dismissed result into the page after Playwright handles it.

No browser dialog handled.

Accessible application modals

Native dialog primitives provide a focus boundary and Escape behavior; every close path reports visibly.

Toast notifications

Success and info use status semantics; error and warning use alert semantics. Delay and dismissal are controlled.

No toast shown.

Passing examples

Start with observable behavior

These snippets match executable tests stored inexamples/playwright-ts/.

Handle a browser prompt
page.on('dialog', async (dialog) => {
  expect(dialog.type()).toBe('prompt');
  expect(dialog.message()).toBe('Name this synthetic run');
  await dialog.accept('Nightly 4803');
});
await page.getByRole('button', { name: 'Open prompt' }).click();
await expect(page.getByTestId('browser-dialog-result')).toContainText('Nightly 4803');
Assert toast semantics
await page.getByRole('button', { name: 'Show success toast' }).click();
await expect(page.getByRole('status').filter({ hasText: 'Saved successfully' })).toBeVisible();