Playwright Assertions | Bondar Academy
Course: Playwright UI Testing with TypeScript
Module: Locators and Assertions
Instructor: Artem Bondar
Lesson Summary
Assertions are a crucial component of test case validation. Without them, a test lacks purpose. In this lesson, we explore two types of assertions in Playwright: generic assertions and locator assertions . Generic Assertions Format: expect(value).toEqual(expectedValue) Example: const value = 5; expect(value).toEqual(5); Behavior: Validates if the left value equals the right value. Methods: Includes toBe , toHaveLength , and more. Locator Assertions Format: expect(locator).toHaveText(expectedText) Example: expect(buttonLocator).toHaveText('submit'); Behavior: Validates the state of a web element and waits for the expected outcome, up to five seconds. Must include a wait before the assertion to ensure stability. Soft Assertions Format: expect.soft(value).toEqual(expectedValue) Behavior: Allows the test to continue execution even if the assertion fails. Example: The test will report the failure but proceed to the next steps. In summary, Playwright offers generic assertions for simple value comparisons and locator assertions for more complex validations that include waiting for conditions. Additionally, soft assertions enable tests to continue running despite failures. For further learning, a link to a YouTube video with more examples will be provided.