chore: make visible=false work (#34040)

This commit is contained in:
Pavel Feldman 2024-12-16 14:14:51 -08:00 committed by GitHub
parent b58a4762f4
commit 94d0fc780d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 14 additions and 1 deletions

View File

@ -457,7 +457,8 @@ export class InjectedScript {
const queryAll = (root: SelectorRoot, body: string) => {
if (root.nodeType !== 1 /* Node.ELEMENT_NODE */)
return [];
return isElementVisible(root as Element) === Boolean(body) ? [root as Element] : [];
const visible = body === 'true';
return isElementVisible(root as Element) === visible ? [root as Element] : [];
};
return { queryAll };
}

View File

@ -74,6 +74,18 @@ it('should work with >> visible=', async ({ page }) => {
expect(await page.$eval('div >> visible=true', div => div.id)).toBe('target2');
});
it('should work with >> visible=false', async ({ page }) => {
await page.setContent(`
<section>
<div id=target1></div>
<div id=target2></div>
</section>
`);
await expect(page.locator('div >> visible=false')).toHaveCount(2);
await page.locator('#target2').evaluate(div => div.textContent = 'Now visible');
await expect(page.locator('div >> visible=false')).toHaveCount(1);
});
it('should work with :nth-match', async ({ page }) => {
await page.setContent(`
<section>