Skip to content
masterclass Buddy

Playwright · Matcher

toHaveClass

Use expect(locator).toHaveClass() to verify an element's CSS class property. The assertion retries until the expected class condition passes or the assertion timeout is reached.

Last updated

Syntax

await expect(locator).toHaveClass(expected);

In-depth API docs are only for subscribers: parameters, examples, common mistakes and interview practice.

Subscribe
  • expect
  • Locator
  • toHaveText
  • toBeVisible
  • expect.poll
  • expect.toPass

Source: Assertions | Playwright. Checked 2026-11-03.