CodePark/ questions / End-to-end (Playwright)
START PRACTICINGPRACTICE
Frontend question · Testing › End-to-end (Playwright)

Why is the first assertion flaky while the second is not?

// A
expect(await page.getByText("Welcome").isVisible()).toBe(true);

// B
await expect(page.getByText("Welcome")).toBeVisible();
A checks visibility once at that instant; B retries until the element is visible or the timeout passes

A checks visibility once, at that instant. B retries until the element is visible or the timeout passes. isVisible() returns the current state at once, without waiting. The generic toBe can't retry either. Web-first matchers on a locator, like toBeVisible, keep polling. This handles elements that appear after a network request or an animation. The option saying B is flaky too is wrong, because B retries.