Testing / Playwright Interview questions
What is the difference between expect().toBeVisible() and isVisible()?
Both check visibility, but they're built for different purposes and behave very differently under the hood.
| expect(locator).toBeVisible() | locator.isVisible() |
| Retries until true or timeout | Checks once, immediately |
| Throws a descriptive error on failure | Returns a plain boolean, never throws |
| Meant to be the test's actual verification step | Meant for conditional branching in test logic |
Using isVisible() as if it were an assertion is a common source of flaky tests, because it returns false instantly if the element simply hasn't rendered yet, instead of waiting for it - it's built for "if this happens, do X" logic, not for proving something is true.
More Related questions...