Skip to content
CodeKruPro

expect - toHaveText

34/70

Playwright Assertions: toHaveText

await expect(locator).toHaveText(expected) asserts the element's text content matches. It supports exact strings and regex.

Task:

  1. Navigate to https://testkru.com/Elements/TextMessages
  2. Assert that #boldText has text "A Bold Text"
  3. Assert that #italicText has text matching regex /Italic/
  4. Print confirmation after each

Expected output:

Bold text assertion: PASS
Italic regex assertion: PASS