Playwright + Java · Lesson 19 of 38
Module 19: Assertions
Your task
Implement verifyDashboardPage:
Write it in the editor, then press Check answer (Ctrl + Enter).
import static com.microsoft.playwright.assertions.PlaywrightAssertions.assertThat;
assertThat(page).hasURL("https://targetqa.com/dashboard");
assertThat(page).hasTitle("Dashboard - TargetQA");
Locator welcomeHeader = page.getByRole(AriaRole.HEADING);
assertThat(welcomeHeader).isVisible();
assertThat(welcomeHeader).hasText("Welcome back, Dhanu!");Web-first assertions are Playwright's most powerful weapon against test flakiness. Unlike JUnit assertEquals which checks values only once, PlaywrightAssertions automatically re-poll the element until the expected condition is met or the timeout expires. Let's master web-first assertions!
Part of the Playwright + Java course (Playwright with Java). Practice this concept live in the Playwright Online Compiler or explore our free automation practice form.
locator.isVisible() checks the DOM only at that exact millisecond without auto-retrying. assertThat(locator).isVisible() continuously polls the DOM until visible.
Ready? Solve the task in the editor
Use Check answer to mark it complete. Hints are there if you need them.
___