Sparround

Assertions and fixtures

Web-first assertions auto-retry until the condition holds (5s default):

  • await expect(locator).toBeVisible() / toHaveText('...') / toHaveCount(3)
  • await expect(page).toHaveURL(/checkout/)
  • Negative: await expect(locator).toBeHidden() — verifies ABSENCE with waiting too

Plain value assertions (no retry): expect(total).toBe(100) — for API responses and calculations.

Fixtures are Playwright's setup/teardown mechanism: the page in test('...', async ({ page, context }) => ...) is itself a fixture. Writing your own: test.extend<{ loggedInPage: Page }>({...}) — setup before await use(...), teardown after. Advantages over beforeEach: composition, typing, lazy instantiation.

A good test follows AAA: Arrange (prep — data, page), Act (the action under test), Assert (verify the outcome). One test — one behaviour; a 15-assertion "checks everything" test doesn't say WHAT broke when it fails.

📚 Sources and documentation