Playwright Assertions | Bondar Academy
Course: Playwright UI Testing with TypeScript
Module: Locators and Assertions
Instructor: Artem Bondar
Lesson Summary
In this lesson, we explore assertions in Playwright, focusing on the differences between three main types: generic assertions , locator assertions , and soft assertions . Types of Assertions Generic Assertions Example syntax: expect(value).toEqual(expectedValue) . Common methods include: toBe toEqual toContain toHaveLength Locator Assertions These assertions interact with web elements and can wait for conditions. Example syntax: await expect(locator).toHaveText('submit') . They include methods like: toBeAttached toBeChecked toHaveText Locator assertions have a timeout of up to five seconds. Soft Assertions Allow tests to continue execution even if an assertion fails. Example syntax: await expect.soft(locator).toHaveText('submit') . Considered less ideal for regular testing practices. Key Takeaways In summary, Playwright offers: Generic Assertions that do not wait for conditions. Locator Assertions that wait for elements and are more interactive. Soft Assertions that allow tests to proceed despite failures. Understanding these differences is crucial for effective testing in Playwright. See you in the next lesson!