test: out-of-viewport should be considered visible (#13134)

Closes #13131.

Per the visibility spec on https://playwright.dev/docs/next/actionability#visible:

> Element is considered visible when it has non-empty bounding box and does not have visibility:hidden computed style. Note that elements of zero size or with display:none are not considered visible.

 non-empty bounding box
 does not have visibility:hidden

Given the above conditions are satisfied, the locator is considered visible.

https://github.com/microsoft/playwright/issues/8740 proposes something like `isInViewport()` that would be better suited for checking if an element is offscreen.
This commit is contained in:
Ross Wollman 2022-03-28 16:10:16 -07:00 committed by GitHub
parent ae365dda3b
commit 13dedd27ca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 21 additions and 0 deletions

View File

@ -67,6 +67,27 @@ it('should wait for visible recursively', async ({ page, server }) => {
expect(divVisible).toBe(true);
});
it('should consider outside of viewport visible', async ({ page }) => {
await page.setContent(`
<style>
.cover {
position: fixed;
left: 0;
top: 0;
width: 100px;
height: 100px;
background-color: red;
transform: translateX(-200px);
}
</style>
<div class="cover">cover</div>
`);
const cover = page.locator('.cover');
await cover.waitFor({ state: 'visible' });
await expect(cover).toBeVisible();
});
it('hidden should wait for hidden', async ({ page, server }) => {
let divHidden = false;
await page.setContent(`<div style='display: block;'>content</div>`);