10. Web-First PlaywrightAssertions & Auto-Waiting

Web-First Assertions with assertThat

import static com.microsoft.playwright.assertions.PlaywrightAssertions.assertThat;

// Visibility & State:
assertThat(page.getByRole(AriaRole.BUTTON, new Page.GetByRoleOptions().setName("Checkout"))).isVisible();
assertThat(page.getByLabel("Terms")).isChecked();

// Text & Value:
assertThat(page.getByTestId("cart-count")).hasText("2");
assertThat(page).hasURL("https://targetqa.com/cart");

Task

  • Implement getAssertionMessage:
  • 1. Accept boolean passed and String label.
  • 2. Return passed ? "PASSED: " + label : "FAILED: " + label.
πŸ’‘Common doubts
Did you like the problem?
Lesson 10 of 18
Java
Loading code editor…
Next