-
Notifications
You must be signed in to change notification settings - Fork 3.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Feature]: Extend isVisible/toBeVisible API to include overlap detection #34778
Comments
This feature will help in accessibility testing - checking if all the buttons do not overlap when the browser's zoom is set to more than 100% and smaller viewports. 👍 |
The use of |
@VGervasio No, viewport does not consider other elements, it only checks whether the element is inside/outside of the screen. I've added that to the example too. |
I thought that if the other elements blocked the visibility of the element |
@VGervasio At first, I also assumed that, but then I dug a bit deeper, and I found that viewport detection relies on the Intersection Observer API and compares it with the device's viewport. And if I understood correctly, there is no way to achieve real overlap detection using the Intersection Observer API. You can read more about it here. |
🚀 Feature Request
Extend the
isVisible
andtoBeVisible
calls to have an optional flagcheckOverlaps
(orenforceNotOverlapped
if we want to be more precise), which would check if the element is overlapped by another one and thus not visible. For backward-compatibility, the flag would have a default value offalse
, in which caseisVisible
/toBeVisible
would work exactly the same way as it does now.If there is a strong argument for keeping these existing APIs unchanged, a new method could also be introduced (e.g.
isNotOverlapped
/toBeNotOverlapped
).Here's a possible implementation (does not consider transformations yet) that we use in our codebase to check overlaps.
Example
Motivation
As described in this previous issue (as well as this one),
isVisible
currently does not consider overlaps at all, so if an element is fully behind another one,isVisible
may still returntrue
for it. It would be useful to be able to test that an element is actually visible on the screen, since some visual bugs can offer due to overlapping elements and these are currently hard to write tests for using Playwright. Modern web apps often feature a lot of popups, modals etc. that may overlap other content on the screen.The text was updated successfully, but these errors were encountered: