Playwright Assertions: toHaveText
await expect(locator).toHaveText(expected) asserts the element's text content matches. It supports exact strings and regex.
Task:
- Navigate to
https://testkru.com/Elements/TextMessages - Assert that
#boldTexthas text "A Bold Text" - Assert that
#italicTexthas text matching regex/Italic/ - Print confirmation after each
Expected output:
Bold text assertion: PASS Italic regex assertion: PASS
TestKru