19. Web-First Retrying Assertions & Soft Validations

Web-First Assertions with Automatic Retry

// Visibility & State:
await expect(page.getByRole("button", { name: "Submit" })).toBeVisible();
await expect(page.getByRole("button", { name: "Submit" })).toBeEnabled();
await expect(page.getByLabel("Subscribe")).toBeChecked();

// Text & Values:
await expect(page.getByTestId("cart-count")).toHaveText("3");
await expect(page).toHaveURL("https://targetqa.com/dashboard");

// Soft assertions (allow test to continue after failure):
await expect.soft(page.getByTestId("subtotal")).toHaveText("$50.00");
await expect.soft(page.getByTestId("tax")).toHaveText("$5.00");

Task

  • Implement formatAssertionResult:
  • 1. Accept field, expected, and actual strings.
  • 2. Return `Assertion Failed: [${field}] Expected '${expected}', but received '${actual}'.`.
πŸ’‘Common doubts
Did you like the problem?
Lesson 19 of 35
JavaScript
Loading code editor…
Next